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;
class SegTree {
public:
int sz;
vector<int> tree;
SegTree(int sz) : sz(sz), tree(2 * sz, 0) {}
void Update(int p, int x) {
for (p += sz; p > 0; p /= 2) tree[p] += x;
}
int Query(int l, int r) {
int res = 0 ;
for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
if (l & 1) res += tree[l++];
if (r & 1) res += tree[--r];
}
return res;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
const int MAX = 1e6 + 5;
SegTree seg(MAX);
int ans = 0;
for (int i = 0, j; i < N; i = j + 1) {
ans += 1;
for (j = i; j + 1 < N && A[j] <= A[j + 1] && seg.Query(A[i] + 1, A[j + 1]) == 0; j++);
for (int k = i; k <= j; k++) {
seg.Update(A[k], 1);
}
}
cout << ans << '\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... |