#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, a[200200], t[1001001], N;
vector<int> X;
vector<array<int, 2>> query;
void update(int b, int x) {
while(b <= N) t[b] += x, b += b & -b;
}
int find(int b) {
int re = 0;
while(b) re += t[b], b -= b & -b;
return re;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) X.push_back(a[i]), X.push_back(a[i]+1);
for(int i=1;i<=m;i++) {
int q; cin >> q;
if(q == 1) {
int x; cin >> x;
X.push_back(x);
query.push_back({0, x});
} else {
int x, y; cin >> x >> y;
X.push_back(y), X.push_back(y);
query.push_back({x, y});
}
}
sort(X.begin(), X.end()), X.erase(unique(X.begin(), X.end()), X.end());
N = X.size();
for(int i=1;i<=n;i++) a[i] = lower_bound(X.begin(), X.end(), a[i]) - X.begin() + 1;
for(int i=1;i<n;i++) if(a[i] != a[i+1]) update(min(a[i], a[i+1])+1, 1), update(max(a[i], a[i+1])+1, -1);
for(auto [x, y] : query) {
y = lower_bound(X.begin(), X.end(), y) - X.begin() + 1;
if(x) {
for(int i=max(1,x-1);i<=min(n-1,x);i++) if(a[i] != a[i+1]) {
update(min(a[i], a[i+1])+1, -1), update(max(a[i], a[i+1])+1, 1);
}
a[x] = y;
for(int i=max(1,x-1);i<=min(n-1,x);i++) if(a[i] != a[i+1]) {
update(min(a[i], a[i+1])+1, 1), update(max(a[i], a[i+1])+1, -1);
}
} else {
int k = find(y);
if(a[1] >= y) cout << (k+2)/2 << "\n";
else cout << (k+1)/2 << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2584 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2648 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2656 KB |
Output is correct |
13 |
Correct |
2 ms |
2520 KB |
Output is correct |
14 |
Correct |
2 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2676 KB |
Output is correct |
3 |
Correct |
2 ms |
2524 KB |
Output is correct |
4 |
Correct |
12 ms |
3532 KB |
Output is correct |
5 |
Correct |
23 ms |
6364 KB |
Output is correct |
6 |
Correct |
37 ms |
6996 KB |
Output is correct |
7 |
Correct |
62 ms |
8268 KB |
Output is correct |
8 |
Correct |
74 ms |
9096 KB |
Output is correct |
9 |
Correct |
141 ms |
12360 KB |
Output is correct |
10 |
Correct |
118 ms |
12436 KB |
Output is correct |
11 |
Correct |
153 ms |
13388 KB |
Output is correct |
12 |
Correct |
167 ms |
14432 KB |
Output is correct |
13 |
Correct |
165 ms |
18112 KB |
Output is correct |
14 |
Correct |
162 ms |
15060 KB |
Output is correct |
15 |
Correct |
172 ms |
15524 KB |
Output is correct |
16 |
Correct |
176 ms |
17216 KB |
Output is correct |
17 |
Correct |
166 ms |
17400 KB |
Output is correct |
18 |
Correct |
167 ms |
16948 KB |
Output is correct |
19 |
Correct |
165 ms |
17884 KB |
Output is correct |
20 |
Correct |
166 ms |
18024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2584 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2648 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2656 KB |
Output is correct |
13 |
Correct |
2 ms |
2520 KB |
Output is correct |
14 |
Correct |
2 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2676 KB |
Output is correct |
18 |
Correct |
2 ms |
2524 KB |
Output is correct |
19 |
Correct |
12 ms |
3532 KB |
Output is correct |
20 |
Correct |
23 ms |
6364 KB |
Output is correct |
21 |
Correct |
37 ms |
6996 KB |
Output is correct |
22 |
Correct |
62 ms |
8268 KB |
Output is correct |
23 |
Correct |
74 ms |
9096 KB |
Output is correct |
24 |
Correct |
141 ms |
12360 KB |
Output is correct |
25 |
Correct |
118 ms |
12436 KB |
Output is correct |
26 |
Correct |
153 ms |
13388 KB |
Output is correct |
27 |
Correct |
167 ms |
14432 KB |
Output is correct |
28 |
Correct |
165 ms |
18112 KB |
Output is correct |
29 |
Correct |
162 ms |
15060 KB |
Output is correct |
30 |
Correct |
172 ms |
15524 KB |
Output is correct |
31 |
Correct |
176 ms |
17216 KB |
Output is correct |
32 |
Correct |
166 ms |
17400 KB |
Output is correct |
33 |
Correct |
167 ms |
16948 KB |
Output is correct |
34 |
Correct |
165 ms |
17884 KB |
Output is correct |
35 |
Correct |
166 ms |
18024 KB |
Output is correct |
36 |
Correct |
1 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
14 ms |
5624 KB |
Output is correct |
40 |
Correct |
24 ms |
6408 KB |
Output is correct |
41 |
Correct |
47 ms |
7140 KB |
Output is correct |
42 |
Correct |
61 ms |
7952 KB |
Output is correct |
43 |
Correct |
88 ms |
10180 KB |
Output is correct |
44 |
Correct |
162 ms |
16592 KB |
Output is correct |
45 |
Correct |
132 ms |
12304 KB |
Output is correct |
46 |
Correct |
151 ms |
13956 KB |
Output is correct |
47 |
Correct |
193 ms |
16576 KB |
Output is correct |
48 |
Correct |
201 ms |
16832 KB |
Output is correct |
49 |
Correct |
188 ms |
16828 KB |
Output is correct |
50 |
Correct |
194 ms |
16844 KB |
Output is correct |
51 |
Correct |
198 ms |
16848 KB |
Output is correct |
52 |
Correct |
194 ms |
17340 KB |
Output is correct |
53 |
Correct |
195 ms |
17600 KB |
Output is correct |
54 |
Correct |
196 ms |
16828 KB |
Output is correct |
55 |
Correct |
200 ms |
18108 KB |
Output is correct |