#include <bits/stdc++.h>
#define N 1000050
using namespace std;
int bit[N], v[N], n, ans;
void upd(int x, int v)
{
for(int i = x; i < N; i += (i&-i)) bit[i] += v;
}
int query(int x)
{
int sum = 0;
for(int i = x; i > 0; i -= (i&-i)) sum += bit[i];
return sum;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1; i <= n; i++) cin>>v[i];
for(int i = 1; i <= n; i++)
{
int st = i, ant = v[i];
ans ++;
while(i <= n and v[i] >= ant)
{
int A = min(v[i], v[st] - 1), B = max(v[i], v[st] - 1);
A ++, B --;
if(A <= B and query(B) - query(A)) break;
ant = v[i];
i ++;
}
for(int j = st; j < i; j++) upd(v[j], 1);
i --;
}
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
2 ms |
608 KB |
Output is correct |
14 |
Correct |
2 ms |
608 KB |
Output is correct |
15 |
Correct |
2 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
2 ms |
608 KB |
Output is correct |
14 |
Correct |
2 ms |
608 KB |
Output is correct |
15 |
Correct |
2 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
2 ms |
840 KB |
Output is correct |
23 |
Correct |
2 ms |
840 KB |
Output is correct |
24 |
Correct |
2 ms |
840 KB |
Output is correct |
25 |
Correct |
2 ms |
840 KB |
Output is correct |
26 |
Correct |
2 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
2 ms |
608 KB |
Output is correct |
14 |
Correct |
2 ms |
608 KB |
Output is correct |
15 |
Correct |
2 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
2 ms |
840 KB |
Output is correct |
23 |
Correct |
2 ms |
840 KB |
Output is correct |
24 |
Correct |
2 ms |
840 KB |
Output is correct |
25 |
Correct |
2 ms |
840 KB |
Output is correct |
26 |
Correct |
2 ms |
840 KB |
Output is correct |
27 |
Correct |
2 ms |
840 KB |
Output is correct |
28 |
Correct |
3 ms |
840 KB |
Output is correct |
29 |
Correct |
2 ms |
840 KB |
Output is correct |
30 |
Correct |
2 ms |
840 KB |
Output is correct |
31 |
Correct |
2 ms |
840 KB |
Output is correct |
32 |
Correct |
2 ms |
840 KB |
Output is correct |
33 |
Correct |
2 ms |
840 KB |
Output is correct |
34 |
Correct |
2 ms |
840 KB |
Output is correct |
35 |
Correct |
3 ms |
840 KB |
Output is correct |
36 |
Correct |
2 ms |
840 KB |
Output is correct |
37 |
Correct |
3 ms |
1924 KB |
Output is correct |
38 |
Correct |
3 ms |
2052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
2 ms |
608 KB |
Output is correct |
14 |
Correct |
2 ms |
608 KB |
Output is correct |
15 |
Correct |
2 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
2 ms |
840 KB |
Output is correct |
23 |
Correct |
2 ms |
840 KB |
Output is correct |
24 |
Correct |
2 ms |
840 KB |
Output is correct |
25 |
Correct |
2 ms |
840 KB |
Output is correct |
26 |
Correct |
2 ms |
840 KB |
Output is correct |
27 |
Correct |
2 ms |
840 KB |
Output is correct |
28 |
Correct |
3 ms |
840 KB |
Output is correct |
29 |
Correct |
2 ms |
840 KB |
Output is correct |
30 |
Correct |
2 ms |
840 KB |
Output is correct |
31 |
Correct |
2 ms |
840 KB |
Output is correct |
32 |
Correct |
2 ms |
840 KB |
Output is correct |
33 |
Correct |
2 ms |
840 KB |
Output is correct |
34 |
Correct |
2 ms |
840 KB |
Output is correct |
35 |
Correct |
3 ms |
840 KB |
Output is correct |
36 |
Correct |
2 ms |
840 KB |
Output is correct |
37 |
Correct |
3 ms |
1924 KB |
Output is correct |
38 |
Correct |
3 ms |
2052 KB |
Output is correct |
39 |
Correct |
99 ms |
2564 KB |
Output is correct |
40 |
Correct |
129 ms |
3876 KB |
Output is correct |
41 |
Correct |
63 ms |
3876 KB |
Output is correct |
42 |
Correct |
60 ms |
3876 KB |
Output is correct |
43 |
Correct |
41 ms |
3876 KB |
Output is correct |
44 |
Correct |
188 ms |
4612 KB |
Output is correct |
45 |
Correct |
158 ms |
4724 KB |
Output is correct |
46 |
Correct |
174 ms |
4724 KB |
Output is correct |
47 |
Correct |
157 ms |
4724 KB |
Output is correct |
48 |
Correct |
172 ms |
4724 KB |
Output is correct |
49 |
Correct |
170 ms |
8452 KB |
Output is correct |
50 |
Correct |
206 ms |
8508 KB |
Output is correct |
51 |
Correct |
201 ms |
8516 KB |
Output is correct |
52 |
Correct |
206 ms |
8516 KB |
Output is correct |
53 |
Correct |
178 ms |
8516 KB |
Output is correct |
54 |
Correct |
172 ms |
8516 KB |
Output is correct |
55 |
Correct |
199 ms |
8516 KB |
Output is correct |
56 |
Correct |
180 ms |
8516 KB |
Output is correct |
57 |
Correct |
209 ms |
8516 KB |
Output is correct |
58 |
Correct |
222 ms |
8516 KB |
Output is correct |
59 |
Correct |
234 ms |
8516 KB |
Output is correct |
60 |
Correct |
221 ms |
8556 KB |
Output is correct |
61 |
Correct |
206 ms |
8556 KB |
Output is correct |
62 |
Correct |
199 ms |
8580 KB |
Output is correct |