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;
const int mxN = 1000006;
struct fwtree {
int ar[mxN];
void add(int i, int x) {
for (++ i; i < mxN; i += i & -i) {
ar[i] += x;
}
}
int qry(int i) {
int r = 0;
for (++ i; i; i -= i & -i) {
r += ar[i];
}
return r;
}
int qry(int i, int j) {
if (i > j) {
return 0;
} else {
return qry(j) - qry(i - 1);
}
}
} fw;
int a[mxN];
void solve() {
int N;
cin >> N;
for (int i = 0; i < N; i ++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < N; i ++) {
int d = a[i];
int c = i;
for (int j = i + 1; j < N; j ++) {
if (a[j - 1] <= a[j] && 0 == fw.qry(d + 1, a[j] - 1)) {
i = j;
} else {
break;
}
}
for (; c <= i; c ++) {
fw.add(a[c], 1);
}
ans ++;
}
cout << ans << endl;
}
int main() {
solve();
}
# | 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... |