#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const ll N = 1e6+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int a[N] , t[N] , n;
void upd(int i){
for(; i < N; i = (i|(i+1))) t[i]++;
}
int get(int i){
int res = 0;
for(; i > 0; i = (i & (i + 1)) - 1) res += t[i];
return res;
}
int gett(int l , int r){
if(r < l) return 0;
return get(r)-get(l-1);
}
void solve(){
cin >> n;
for(ll i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for(int i = 1; i <= n; i++){
int st = i;
while(a[i] <= a[i+1] && gett(a[st]+1,a[i+1]-1) == 0) i++;
for(int j = st; j <= i; j++) upd(a[j]);
ans++;
}
cout << ans << "\n";
}
/*
*/
signed main(){
ios;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4568 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2548 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
4556 KB |
Output is correct |
11 |
Correct |
1 ms |
2512 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4568 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2548 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
4556 KB |
Output is correct |
11 |
Correct |
1 ms |
2512 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4568 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2548 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
4556 KB |
Output is correct |
11 |
Correct |
1 ms |
2512 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2508 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
3164 KB |
Output is correct |
38 |
Correct |
1 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4560 KB |
Output is correct |
4 |
Correct |
1 ms |
4568 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2548 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
4556 KB |
Output is correct |
11 |
Correct |
1 ms |
2512 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2508 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
3164 KB |
Output is correct |
38 |
Correct |
1 ms |
3160 KB |
Output is correct |
39 |
Correct |
45 ms |
7612 KB |
Output is correct |
40 |
Correct |
78 ms |
12488 KB |
Output is correct |
41 |
Correct |
37 ms |
7000 KB |
Output is correct |
42 |
Correct |
34 ms |
6740 KB |
Output is correct |
43 |
Correct |
27 ms |
6232 KB |
Output is correct |
44 |
Correct |
100 ms |
12724 KB |
Output is correct |
45 |
Correct |
89 ms |
12632 KB |
Output is correct |
46 |
Correct |
94 ms |
12732 KB |
Output is correct |
47 |
Correct |
82 ms |
12900 KB |
Output is correct |
48 |
Correct |
90 ms |
12908 KB |
Output is correct |
49 |
Correct |
114 ms |
14924 KB |
Output is correct |
50 |
Correct |
100 ms |
14960 KB |
Output is correct |
51 |
Correct |
95 ms |
14916 KB |
Output is correct |
52 |
Correct |
99 ms |
15024 KB |
Output is correct |
53 |
Correct |
101 ms |
14840 KB |
Output is correct |
54 |
Correct |
113 ms |
14672 KB |
Output is correct |
55 |
Correct |
108 ms |
15180 KB |
Output is correct |
56 |
Correct |
103 ms |
14920 KB |
Output is correct |
57 |
Correct |
102 ms |
14904 KB |
Output is correct |
58 |
Correct |
103 ms |
14928 KB |
Output is correct |
59 |
Correct |
104 ms |
14912 KB |
Output is correct |
60 |
Correct |
103 ms |
14932 KB |
Output is correct |
61 |
Correct |
105 ms |
14788 KB |
Output is correct |
62 |
Correct |
103 ms |
14900 KB |
Output is correct |