#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 2e6 + 11;
const int MAX = 1e6;
ll n, res, ans;
ll a[N], t[4 * N];
void upd(ll k, ll x, ll v = 1, ll l = 1, ll r = MAX){
if(l == r){
t[v] += x;
return;
}
ll md = (l + r) / 2;
if(k <= md) upd(k, x, v + v, l, md);
else upd(k, x, v + v + 1, md + 1, r);
t[v] = t[v + v] + t[v + v + 1];
}
ll get(ll tl, ll tr, ll v = 1, ll l = 1, ll r = MAX){
if(r < tl || tr < l) return 0;
if(tl <= l && r <= tr) return t[v];
ll md = (l + r) / 2;
return get(tl, tr, v + v, l, md) + get(tl, tr, v + v + 1, md + 1, r);
}
void sol(){
cin >> n, res = ans = 0;
for(ll i = 1; i <= n; i++) cin >> a[i];
for(ll i = 1; i <= n;){
ll j = i;
while(j <= n && a[j] <= a[j + 1] && get(a[i] + 1, a[j + 1] - 1) == 0) j++;
while(i <= j) upd(a[i], 1), i++;
res++;
}
cout << res;
}
signed main(){
ios
sol();
// slow();
// stress();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
1 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
848 KB |
Output is correct |
26 |
Correct |
2 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
1 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
848 KB |
Output is correct |
26 |
Correct |
2 ms |
848 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
592 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
592 KB |
Output is correct |
36 |
Correct |
2 ms |
592 KB |
Output is correct |
37 |
Correct |
4 ms |
3580 KB |
Output is correct |
38 |
Correct |
3 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
1 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
848 KB |
Output is correct |
26 |
Correct |
2 ms |
848 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
592 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
592 KB |
Output is correct |
36 |
Correct |
2 ms |
592 KB |
Output is correct |
37 |
Correct |
4 ms |
3580 KB |
Output is correct |
38 |
Correct |
3 ms |
3408 KB |
Output is correct |
39 |
Correct |
92 ms |
7428 KB |
Output is correct |
40 |
Correct |
166 ms |
12232 KB |
Output is correct |
41 |
Correct |
82 ms |
6216 KB |
Output is correct |
42 |
Correct |
73 ms |
5968 KB |
Output is correct |
43 |
Correct |
50 ms |
4432 KB |
Output is correct |
44 |
Correct |
227 ms |
15196 KB |
Output is correct |
45 |
Correct |
223 ms |
15176 KB |
Output is correct |
46 |
Correct |
200 ms |
15496 KB |
Output is correct |
47 |
Correct |
235 ms |
15176 KB |
Output is correct |
48 |
Correct |
220 ms |
15204 KB |
Output is correct |
49 |
Correct |
354 ms |
31304 KB |
Output is correct |
50 |
Correct |
329 ms |
31524 KB |
Output is correct |
51 |
Correct |
343 ms |
31276 KB |
Output is correct |
52 |
Correct |
361 ms |
31304 KB |
Output is correct |
53 |
Correct |
362 ms |
31560 KB |
Output is correct |
54 |
Correct |
369 ms |
31348 KB |
Output is correct |
55 |
Correct |
461 ms |
31376 KB |
Output is correct |
56 |
Correct |
518 ms |
31544 KB |
Output is correct |
57 |
Correct |
388 ms |
31304 KB |
Output is correct |
58 |
Correct |
400 ms |
31236 KB |
Output is correct |
59 |
Correct |
423 ms |
31304 KB |
Output is correct |
60 |
Correct |
484 ms |
31304 KB |
Output is correct |
61 |
Correct |
482 ms |
31448 KB |
Output is correct |
62 |
Correct |
457 ms |
31304 KB |
Output is correct |