#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2532 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2532 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
484 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
2516 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2532 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
484 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
2516 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Correct |
1 ms |
4432 KB |
Output is correct |
29 |
Correct |
1 ms |
4432 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
4432 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
504 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
1784 KB |
Output is correct |
38 |
Correct |
2 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2532 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
484 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
2516 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Correct |
1 ms |
4432 KB |
Output is correct |
29 |
Correct |
1 ms |
4432 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
4432 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
504 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
1784 KB |
Output is correct |
38 |
Correct |
2 ms |
1784 KB |
Output is correct |
39 |
Correct |
108 ms |
5844 KB |
Output is correct |
40 |
Correct |
196 ms |
11988 KB |
Output is correct |
41 |
Correct |
84 ms |
5192 KB |
Output is correct |
42 |
Correct |
79 ms |
5084 KB |
Output is correct |
43 |
Correct |
57 ms |
4424 KB |
Output is correct |
44 |
Correct |
226 ms |
11344 KB |
Output is correct |
45 |
Correct |
231 ms |
11352 KB |
Output is correct |
46 |
Correct |
221 ms |
11684 KB |
Output is correct |
47 |
Correct |
201 ms |
11336 KB |
Output is correct |
48 |
Correct |
210 ms |
11484 KB |
Output is correct |
49 |
Correct |
221 ms |
14816 KB |
Output is correct |
50 |
Correct |
223 ms |
14920 KB |
Output is correct |
51 |
Correct |
209 ms |
14920 KB |
Output is correct |
52 |
Correct |
208 ms |
14920 KB |
Output is correct |
53 |
Correct |
209 ms |
14920 KB |
Output is correct |
54 |
Correct |
204 ms |
14664 KB |
Output is correct |
55 |
Correct |
229 ms |
14940 KB |
Output is correct |
56 |
Correct |
229 ms |
14928 KB |
Output is correct |
57 |
Correct |
232 ms |
14800 KB |
Output is correct |
58 |
Correct |
236 ms |
14932 KB |
Output is correct |
59 |
Correct |
244 ms |
14936 KB |
Output is correct |
60 |
Correct |
234 ms |
14936 KB |
Output is correct |
61 |
Correct |
249 ms |
14940 KB |
Output is correct |
62 |
Correct |
231 ms |
14920 KB |
Output is correct |