#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
struct Fenwick{
int N;
vector<int> tree;
Fenwick(int n){
this->N = n;
tree.resize(N+1);
}
int sum(int k) {
int s = 0;
while (k >= 1) {
s += tree[k];
k -= k&-k;
}
return s;
}
void add(int k, int x = 1) {
while (k <= N) {
tree[k] += x;
k += k&-k;
}
}
int query(int l, int r){
if (r < l) return 0;
int ans = sum(r);
if (l > 1) ans -= sum(l-1);
return ans;
}
};
void solve(){
Fenwick bit(1000001);
int n; cin >> n;
vector<int> a(n+1);
FOR(i,1,n+1) cin >> a[i];
int c = 1;
int ans = 0;
FOR(i,1,n+1){
if (a[i] >= a[i-1]){
if (bit.query(a[c]+1, a[i]-1)){
FOR(j,c,i){
bit.add(a[j]);
}
ans++;
c = i;
}
}else{
FOR(j,c,i){
bit.add(a[j]);
}
ans++;
c = i;
}
// cout << ans << " ";
}
// cout << endl;
cout << ans+1 << endl;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
int t = 1; // cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
2 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
2 ms |
8272 KB |
Output is correct |
6 |
Correct |
2 ms |
8272 KB |
Output is correct |
7 |
Correct |
2 ms |
8272 KB |
Output is correct |
8 |
Correct |
2 ms |
8272 KB |
Output is correct |
9 |
Correct |
3 ms |
8272 KB |
Output is correct |
10 |
Correct |
2 ms |
8272 KB |
Output is correct |
11 |
Correct |
2 ms |
8440 KB |
Output is correct |
12 |
Correct |
3 ms |
8272 KB |
Output is correct |
13 |
Correct |
3 ms |
8272 KB |
Output is correct |
14 |
Correct |
3 ms |
8272 KB |
Output is correct |
15 |
Correct |
2 ms |
8272 KB |
Output is correct |
16 |
Correct |
3 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
2 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
2 ms |
8272 KB |
Output is correct |
6 |
Correct |
2 ms |
8272 KB |
Output is correct |
7 |
Correct |
2 ms |
8272 KB |
Output is correct |
8 |
Correct |
2 ms |
8272 KB |
Output is correct |
9 |
Correct |
3 ms |
8272 KB |
Output is correct |
10 |
Correct |
2 ms |
8272 KB |
Output is correct |
11 |
Correct |
2 ms |
8440 KB |
Output is correct |
12 |
Correct |
3 ms |
8272 KB |
Output is correct |
13 |
Correct |
3 ms |
8272 KB |
Output is correct |
14 |
Correct |
3 ms |
8272 KB |
Output is correct |
15 |
Correct |
2 ms |
8272 KB |
Output is correct |
16 |
Correct |
3 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
2 ms |
8272 KB |
Output is correct |
19 |
Correct |
3 ms |
8272 KB |
Output is correct |
20 |
Correct |
2 ms |
8272 KB |
Output is correct |
21 |
Correct |
3 ms |
8272 KB |
Output is correct |
22 |
Correct |
2 ms |
8272 KB |
Output is correct |
23 |
Correct |
2 ms |
8272 KB |
Output is correct |
24 |
Correct |
3 ms |
8272 KB |
Output is correct |
25 |
Correct |
3 ms |
8272 KB |
Output is correct |
26 |
Correct |
4 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
2 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
2 ms |
8272 KB |
Output is correct |
6 |
Correct |
2 ms |
8272 KB |
Output is correct |
7 |
Correct |
2 ms |
8272 KB |
Output is correct |
8 |
Correct |
2 ms |
8272 KB |
Output is correct |
9 |
Correct |
3 ms |
8272 KB |
Output is correct |
10 |
Correct |
2 ms |
8272 KB |
Output is correct |
11 |
Correct |
2 ms |
8440 KB |
Output is correct |
12 |
Correct |
3 ms |
8272 KB |
Output is correct |
13 |
Correct |
3 ms |
8272 KB |
Output is correct |
14 |
Correct |
3 ms |
8272 KB |
Output is correct |
15 |
Correct |
2 ms |
8272 KB |
Output is correct |
16 |
Correct |
3 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
2 ms |
8272 KB |
Output is correct |
19 |
Correct |
3 ms |
8272 KB |
Output is correct |
20 |
Correct |
2 ms |
8272 KB |
Output is correct |
21 |
Correct |
3 ms |
8272 KB |
Output is correct |
22 |
Correct |
2 ms |
8272 KB |
Output is correct |
23 |
Correct |
2 ms |
8272 KB |
Output is correct |
24 |
Correct |
3 ms |
8272 KB |
Output is correct |
25 |
Correct |
3 ms |
8272 KB |
Output is correct |
26 |
Correct |
4 ms |
8272 KB |
Output is correct |
27 |
Correct |
3 ms |
8272 KB |
Output is correct |
28 |
Correct |
2 ms |
8272 KB |
Output is correct |
29 |
Correct |
2 ms |
8272 KB |
Output is correct |
30 |
Correct |
3 ms |
8272 KB |
Output is correct |
31 |
Correct |
3 ms |
8284 KB |
Output is correct |
32 |
Correct |
3 ms |
8272 KB |
Output is correct |
33 |
Correct |
3 ms |
8272 KB |
Output is correct |
34 |
Correct |
4 ms |
8272 KB |
Output is correct |
35 |
Correct |
3 ms |
8272 KB |
Output is correct |
36 |
Correct |
2 ms |
8272 KB |
Output is correct |
37 |
Correct |
3 ms |
8272 KB |
Output is correct |
38 |
Correct |
3 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
2 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
2 ms |
8272 KB |
Output is correct |
6 |
Correct |
2 ms |
8272 KB |
Output is correct |
7 |
Correct |
2 ms |
8272 KB |
Output is correct |
8 |
Correct |
2 ms |
8272 KB |
Output is correct |
9 |
Correct |
3 ms |
8272 KB |
Output is correct |
10 |
Correct |
2 ms |
8272 KB |
Output is correct |
11 |
Correct |
2 ms |
8440 KB |
Output is correct |
12 |
Correct |
3 ms |
8272 KB |
Output is correct |
13 |
Correct |
3 ms |
8272 KB |
Output is correct |
14 |
Correct |
3 ms |
8272 KB |
Output is correct |
15 |
Correct |
2 ms |
8272 KB |
Output is correct |
16 |
Correct |
3 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
2 ms |
8272 KB |
Output is correct |
19 |
Correct |
3 ms |
8272 KB |
Output is correct |
20 |
Correct |
2 ms |
8272 KB |
Output is correct |
21 |
Correct |
3 ms |
8272 KB |
Output is correct |
22 |
Correct |
2 ms |
8272 KB |
Output is correct |
23 |
Correct |
2 ms |
8272 KB |
Output is correct |
24 |
Correct |
3 ms |
8272 KB |
Output is correct |
25 |
Correct |
3 ms |
8272 KB |
Output is correct |
26 |
Correct |
4 ms |
8272 KB |
Output is correct |
27 |
Correct |
3 ms |
8272 KB |
Output is correct |
28 |
Correct |
2 ms |
8272 KB |
Output is correct |
29 |
Correct |
2 ms |
8272 KB |
Output is correct |
30 |
Correct |
3 ms |
8272 KB |
Output is correct |
31 |
Correct |
3 ms |
8284 KB |
Output is correct |
32 |
Correct |
3 ms |
8272 KB |
Output is correct |
33 |
Correct |
3 ms |
8272 KB |
Output is correct |
34 |
Correct |
4 ms |
8272 KB |
Output is correct |
35 |
Correct |
3 ms |
8272 KB |
Output is correct |
36 |
Correct |
2 ms |
8272 KB |
Output is correct |
37 |
Correct |
3 ms |
8272 KB |
Output is correct |
38 |
Correct |
3 ms |
8272 KB |
Output is correct |
39 |
Correct |
56 ms |
15176 KB |
Output is correct |
40 |
Correct |
106 ms |
19760 KB |
Output is correct |
41 |
Correct |
50 ms |
13904 KB |
Output is correct |
42 |
Correct |
46 ms |
13260 KB |
Output is correct |
43 |
Correct |
34 ms |
11632 KB |
Output is correct |
44 |
Correct |
121 ms |
22628 KB |
Output is correct |
45 |
Correct |
114 ms |
22760 KB |
Output is correct |
46 |
Correct |
124 ms |
22756 KB |
Output is correct |
47 |
Correct |
101 ms |
23112 KB |
Output is correct |
48 |
Correct |
107 ms |
22856 KB |
Output is correct |
49 |
Correct |
130 ms |
22856 KB |
Output is correct |
50 |
Correct |
142 ms |
22756 KB |
Output is correct |
51 |
Correct |
134 ms |
22632 KB |
Output is correct |
52 |
Correct |
125 ms |
22888 KB |
Output is correct |
53 |
Correct |
138 ms |
22880 KB |
Output is correct |
54 |
Correct |
126 ms |
22496 KB |
Output is correct |
55 |
Correct |
146 ms |
22600 KB |
Output is correct |
56 |
Correct |
139 ms |
22600 KB |
Output is correct |
57 |
Correct |
144 ms |
22600 KB |
Output is correct |
58 |
Correct |
147 ms |
22624 KB |
Output is correct |
59 |
Correct |
136 ms |
22600 KB |
Output is correct |
60 |
Correct |
141 ms |
22604 KB |
Output is correct |
61 |
Correct |
136 ms |
22624 KB |
Output is correct |
62 |
Correct |
139 ms |
22756 KB |
Output is correct |