#include <bits/stdc++.h>
using namespace std;
class SegTree {
public:
int sz;
vector<int> tree;
SegTree(int sz) : sz(sz), tree(2 * sz, 0) {}
void Update(int l, int r, int v) {
for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
if (l & 1) tree[l++] += v;
if (r & 1) tree[--r] += v;
}
}
int Query(int p) {
int res = 0;
for (p += sz; p > 0; p /= 2) res += tree[p];
return res;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
const int MAX = 1e6 + 5;
SegTree seg(MAX);
const auto Update = [&](int u, int v, int sgn) {
if (min(u, v) < 0 || max(u, v) >= N) return;
u = A[u], v = A[v];
if (u > v) swap(u, v);
seg.Update(u, v, sgn);
};
for (int i = 1; i < N; i++) {
Update(i - 1, i, +1);
}
for (int q = 0; q < M; q++) {
int t;
cin >> t;
if (t == 1) {
int i, v;
cin >> i >> v;
i--;
Update(i - 1, i, -1);
Update(i, i + 1, -1);
A[i] = v;
Update(i - 1, i, +1);
Update(i, i + 1, +1);
} else if (t == 2) {
int h;
cin >> h;
cout << seg.Query(h) << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
5 ms |
8140 KB |
Output is correct |
3 |
Correct |
5 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8136 KB |
Output is correct |
5 |
Correct |
5 ms |
8140 KB |
Output is correct |
6 |
Correct |
6 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
5 ms |
8140 KB |
Output is correct |
3 |
Correct |
5 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8136 KB |
Output is correct |
5 |
Correct |
5 ms |
8140 KB |
Output is correct |
6 |
Correct |
6 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
40 ms |
9480 KB |
Output is correct |
9 |
Correct |
75 ms |
10672 KB |
Output is correct |
10 |
Correct |
74 ms |
10680 KB |
Output is correct |
11 |
Correct |
38 ms |
9412 KB |
Output is correct |
12 |
Correct |
56 ms |
10428 KB |
Output is correct |
13 |
Correct |
56 ms |
10564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
5 ms |
8140 KB |
Output is correct |
3 |
Correct |
5 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8136 KB |
Output is correct |
5 |
Correct |
5 ms |
8140 KB |
Output is correct |
6 |
Correct |
6 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
40 ms |
9480 KB |
Output is correct |
9 |
Correct |
75 ms |
10672 KB |
Output is correct |
10 |
Correct |
74 ms |
10680 KB |
Output is correct |
11 |
Correct |
38 ms |
9412 KB |
Output is correct |
12 |
Correct |
56 ms |
10428 KB |
Output is correct |
13 |
Correct |
56 ms |
10564 KB |
Output is correct |
14 |
Correct |
123 ms |
10700 KB |
Output is correct |
15 |
Correct |
120 ms |
10688 KB |
Output is correct |
16 |
Correct |
123 ms |
10688 KB |
Output is correct |
17 |
Correct |
119 ms |
10744 KB |
Output is correct |
18 |
Correct |
149 ms |
10680 KB |
Output is correct |