#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 1000005
int a[N];
int fen[N];
void update(int x){
while(x < N){
++fen[x];
x += x & -x;
}
}
int query(int x){
int s = 0;
while(x){
s += fen[x];
x -= x & -x;
}
return s;
}
int dp[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int l = 0;
a[0] = 1000005;
for(int i = 1; i <= n; ++i){
cin>>a[i];
if(a[i] < a[i - 1])
while(i != l)
update(a[l++]);
while(l < i && a[i] != a[l] && query(a[i] - 1) != query(a[l])){
update(a[l++]);
}
dp[i] = dp[l - 1] + 1;
}
cout<<dp[n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
632 KB |
Output is correct |
26 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
632 KB |
Output is correct |
26 |
Correct |
2 ms |
632 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
392 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
508 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
1784 KB |
Output is correct |
38 |
Correct |
4 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
632 KB |
Output is correct |
26 |
Correct |
2 ms |
632 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
392 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
508 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
1784 KB |
Output is correct |
38 |
Correct |
4 ms |
1784 KB |
Output is correct |
39 |
Correct |
86 ms |
7392 KB |
Output is correct |
40 |
Correct |
148 ms |
12128 KB |
Output is correct |
41 |
Correct |
73 ms |
6124 KB |
Output is correct |
42 |
Correct |
66 ms |
5620 KB |
Output is correct |
43 |
Correct |
46 ms |
4216 KB |
Output is correct |
44 |
Correct |
181 ms |
15096 KB |
Output is correct |
45 |
Correct |
177 ms |
15096 KB |
Output is correct |
46 |
Correct |
181 ms |
15224 KB |
Output is correct |
47 |
Correct |
162 ms |
15096 KB |
Output is correct |
48 |
Correct |
171 ms |
15096 KB |
Output is correct |
49 |
Correct |
198 ms |
18948 KB |
Output is correct |
50 |
Correct |
203 ms |
18936 KB |
Output is correct |
51 |
Correct |
201 ms |
18780 KB |
Output is correct |
52 |
Correct |
193 ms |
18896 KB |
Output is correct |
53 |
Correct |
201 ms |
18872 KB |
Output is correct |
54 |
Correct |
201 ms |
18680 KB |
Output is correct |
55 |
Correct |
236 ms |
18828 KB |
Output is correct |
56 |
Correct |
233 ms |
18808 KB |
Output is correct |
57 |
Correct |
231 ms |
18808 KB |
Output is correct |
58 |
Correct |
255 ms |
18808 KB |
Output is correct |
59 |
Correct |
226 ms |
18812 KB |
Output is correct |
60 |
Correct |
232 ms |
18892 KB |
Output is correct |
61 |
Correct |
233 ms |
18864 KB |
Output is correct |
62 |
Correct |
224 ms |
18808 KB |
Output is correct |