#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) {
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;
fw.add(d, 1);
for (int j = i + 1; j < N; j ++) {
if (a[j - 1] <= a[j] && j - c == fw.qry(d, a[j])) {
fw.add(a[j], 1);
i = j;
} else {
break;
}
}
ans ++;
}
cout << ans << endl;
}
int main() {
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4656 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4656 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4656 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4656 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |