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 <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e6 + 5, inf = 1e9;
int n;
int a[N], nxt[N], f[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = n; i >= 1; --i) {
nxt[i] = a[i] <= a[i + 1] ? nxt[i + 1] : i;
}
set<int> st{0, inf};
fill(f + 1, f + n + 1, inf);
for (int i = 1; i <= n; ++i) {
int x = *st.upper_bound(a[i]);
int l = i + 1, r = nxt[i], p = i;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] <= x) {
p = m;
l = m + 1;
} else {
r = m - 1;
}
}
f[p] = min(f[p], f[i - 1] + 1);
}
cout << f[n];
return 0;
}
# | 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... |