#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5, M = 1e6 + 5;
int n, m;
int a[N], s[M];
void upd(int i, int x) {
for (; i < M; i += i & -i) {
s[i] += x;
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res += s[i];
}
return res;
}
void add(int u, int v, int x) {
upd(min(u, v), x);
upd(max(u, v) + 1, -x);
}
void chg(int i, int v) {
if (i < n) {
add(a[i], a[i + 1], -1);
}
if (i > 1) {
add(a[i], a[i - 1], -1);
}
a[i] = v;
if (i < n) {
add(a[i], a[i + 1], 1);
}
if (i > 1) {
add(a[i], a[i - 1], 1);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (i > 1) {
add(a[i], a[i - 1], 1);
}
}
while (m--) {
int t; cin >> t;
if (t == 1) {
int p, v; cin >> p >> v;
chg(p, v);
} else {
int h; cin >> h;
cout << qry(h) << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4204 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4204 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
27 ms |
1884 KB |
Output is correct |
9 |
Correct |
39 ms |
6736 KB |
Output is correct |
10 |
Correct |
33 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
1628 KB |
Output is correct |
12 |
Correct |
24 ms |
2948 KB |
Output is correct |
13 |
Correct |
25 ms |
2936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
4188 KB |
Output is correct |
5 |
Correct |
2 ms |
4204 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
27 ms |
1884 KB |
Output is correct |
9 |
Correct |
39 ms |
6736 KB |
Output is correct |
10 |
Correct |
33 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
1628 KB |
Output is correct |
12 |
Correct |
24 ms |
2948 KB |
Output is correct |
13 |
Correct |
25 ms |
2936 KB |
Output is correct |
14 |
Correct |
36 ms |
6736 KB |
Output is correct |
15 |
Correct |
42 ms |
6740 KB |
Output is correct |
16 |
Correct |
38 ms |
6736 KB |
Output is correct |
17 |
Correct |
38 ms |
6740 KB |
Output is correct |
18 |
Correct |
38 ms |
6872 KB |
Output is correct |