#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n;
int a[maxn + 5];
int bit[maxn + 1];
void upd(int k, int v) {
for ( ; k <= maxn; k += (k & -k))
bit[k] += v;
}
int qry(int k) {
int ret = 0;
for (; k; k -= (k & -k))
ret += bit[k];
return ret;
}
int main() {
// freopen("main.in", "r", stdin);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
// figure out nondecreasing sequences
int l = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
// either a[i + 1] < a[i] or element in range
if ((i == n - 1 || a[i + 1] < a[i]) || (a[i + 1] > a[l] && qry(a[i + 1] - 1) - qry(a[l]))) {
for (int j = l; j <= i; j++) upd(a[j], 1);
ans++;
l = i + 1;
}
// if (i == n - 1 || a[i + 1] < a[i]) {
// // [l, i]
// int L = l;
// for (int j = l + 1; j <= i; j++) {
// // cout << l << ' ' << i << ' ' << L << ' ' << j << endl;
// // cout << qry(a[j]-1) << ' ' << qry(a[L]-1) << endl;
// if (a[j] > a[L] && qry(a[j] - 1) - qry(a[L])) {
// ans++;
// L = j + 1; j++;
// }
// }
// for (int k = l; k <= i; k++) {
// upd(a[k], 1);
// }
// ans++;
// l = i + 1;
// }
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
432 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
432 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
304 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
440 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
304 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
1620 KB |
Output is correct |
38 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
428 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
432 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
304 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
440 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
304 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
1620 KB |
Output is correct |
38 |
Correct |
1 ms |
1748 KB |
Output is correct |
39 |
Correct |
154 ms |
5356 KB |
Output is correct |
40 |
Correct |
247 ms |
8816 KB |
Output is correct |
41 |
Correct |
117 ms |
4428 KB |
Output is correct |
42 |
Correct |
106 ms |
4116 KB |
Output is correct |
43 |
Correct |
78 ms |
3080 KB |
Output is correct |
44 |
Correct |
316 ms |
11168 KB |
Output is correct |
45 |
Correct |
302 ms |
10996 KB |
Output is correct |
46 |
Correct |
307 ms |
11196 KB |
Output is correct |
47 |
Correct |
298 ms |
10968 KB |
Output is correct |
48 |
Correct |
299 ms |
11028 KB |
Output is correct |
49 |
Correct |
312 ms |
15028 KB |
Output is correct |
50 |
Correct |
305 ms |
14872 KB |
Output is correct |
51 |
Correct |
341 ms |
14768 KB |
Output is correct |
52 |
Correct |
305 ms |
14796 KB |
Output is correct |
53 |
Correct |
308 ms |
14904 KB |
Output is correct |
54 |
Correct |
305 ms |
14816 KB |
Output is correct |
55 |
Correct |
318 ms |
14796 KB |
Output is correct |
56 |
Correct |
314 ms |
14860 KB |
Output is correct |
57 |
Correct |
314 ms |
14872 KB |
Output is correct |
58 |
Correct |
317 ms |
14956 KB |
Output is correct |
59 |
Correct |
310 ms |
14948 KB |
Output is correct |
60 |
Correct |
311 ms |
14772 KB |
Output is correct |
61 |
Correct |
316 ms |
14912 KB |
Output is correct |
62 |
Correct |
308 ms |
14808 KB |
Output is correct |