#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
8120 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
5 ms |
8128 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
8120 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
5 ms |
8128 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8124 KB |
Output is correct |
17 |
Correct |
5 ms |
8032 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8120 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8124 KB |
Output is correct |
23 |
Correct |
5 ms |
8140 KB |
Output is correct |
24 |
Correct |
5 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
6 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
8120 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
5 ms |
8128 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8124 KB |
Output is correct |
17 |
Correct |
5 ms |
8032 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8120 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8124 KB |
Output is correct |
23 |
Correct |
5 ms |
8140 KB |
Output is correct |
24 |
Correct |
5 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
6 ms |
8140 KB |
Output is correct |
27 |
Correct |
5 ms |
8140 KB |
Output is correct |
28 |
Correct |
5 ms |
8140 KB |
Output is correct |
29 |
Correct |
5 ms |
8140 KB |
Output is correct |
30 |
Correct |
4 ms |
8140 KB |
Output is correct |
31 |
Correct |
4 ms |
8120 KB |
Output is correct |
32 |
Correct |
5 ms |
8140 KB |
Output is correct |
33 |
Correct |
5 ms |
8140 KB |
Output is correct |
34 |
Correct |
4 ms |
8140 KB |
Output is correct |
35 |
Correct |
5 ms |
8120 KB |
Output is correct |
36 |
Correct |
5 ms |
8128 KB |
Output is correct |
37 |
Correct |
4 ms |
8140 KB |
Output is correct |
38 |
Correct |
6 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8064 KB |
Output is correct |
10 |
Correct |
5 ms |
8120 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
5 ms |
8128 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8124 KB |
Output is correct |
17 |
Correct |
5 ms |
8032 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8120 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8124 KB |
Output is correct |
23 |
Correct |
5 ms |
8140 KB |
Output is correct |
24 |
Correct |
5 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
6 ms |
8140 KB |
Output is correct |
27 |
Correct |
5 ms |
8140 KB |
Output is correct |
28 |
Correct |
5 ms |
8140 KB |
Output is correct |
29 |
Correct |
5 ms |
8140 KB |
Output is correct |
30 |
Correct |
4 ms |
8140 KB |
Output is correct |
31 |
Correct |
4 ms |
8120 KB |
Output is correct |
32 |
Correct |
5 ms |
8140 KB |
Output is correct |
33 |
Correct |
5 ms |
8140 KB |
Output is correct |
34 |
Correct |
4 ms |
8140 KB |
Output is correct |
35 |
Correct |
5 ms |
8120 KB |
Output is correct |
36 |
Correct |
5 ms |
8128 KB |
Output is correct |
37 |
Correct |
4 ms |
8140 KB |
Output is correct |
38 |
Correct |
6 ms |
8140 KB |
Output is correct |
39 |
Correct |
117 ms |
13216 KB |
Output is correct |
40 |
Correct |
164 ms |
16440 KB |
Output is correct |
41 |
Correct |
65 ms |
12224 KB |
Output is correct |
42 |
Correct |
68 ms |
11816 KB |
Output is correct |
43 |
Correct |
46 ms |
10656 KB |
Output is correct |
44 |
Correct |
171 ms |
18688 KB |
Output is correct |
45 |
Correct |
165 ms |
18680 KB |
Output is correct |
46 |
Correct |
177 ms |
18804 KB |
Output is correct |
47 |
Correct |
151 ms |
18884 KB |
Output is correct |
48 |
Correct |
150 ms |
18900 KB |
Output is correct |
49 |
Correct |
232 ms |
18852 KB |
Output is correct |
50 |
Correct |
231 ms |
18856 KB |
Output is correct |
51 |
Correct |
245 ms |
18680 KB |
Output is correct |
52 |
Correct |
217 ms |
18848 KB |
Output is correct |
53 |
Correct |
254 ms |
18848 KB |
Output is correct |
54 |
Correct |
243 ms |
18684 KB |
Output is correct |
55 |
Correct |
310 ms |
18668 KB |
Output is correct |
56 |
Correct |
330 ms |
18756 KB |
Output is correct |
57 |
Correct |
322 ms |
18788 KB |
Output is correct |
58 |
Correct |
312 ms |
18796 KB |
Output is correct |
59 |
Correct |
288 ms |
18688 KB |
Output is correct |
60 |
Correct |
286 ms |
18804 KB |
Output is correct |
61 |
Correct |
317 ms |
18792 KB |
Output is correct |
62 |
Correct |
290 ms |
18784 KB |
Output is correct |