This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
int a[N], dp[N], down[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0] = 0;
dp[1] = 1;
down[1] = 1;
for (int i = 2; i <= n; i++) {
down[i] = (a[i] < a[i - 1]) ? i : down[i - 1];
}
for (int i = 2; i <= n; i++) {
int l = down[i], r = i;
while (l <= r) {
int mid = (l + r) / 2;
bool check = true;
int R = 10000000;
for (int j = 1; j < mid; j++) {
if (a[j] > a[mid]) R = min(R, a[j]);
}
if (R < a[i]) check = false;
if (check) {
dp[i] = dp[mid - 1] + 1;
r = mid - 1;
}
else l = mid + 1;
}
}
cout << dp[n] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |