#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int H = 1e6 + 5;
struct fenwick_tree {
int f[H];
fenwick_tree() {
memset(f, 0, sizeof(f));
}
void upd(int i, int x) {
for (; i < H; i += i & -i) {
f[i] += x;
}
}
void upd(int l, int r, int x) {
upd(l, x);
upd(r + 1, -x);
}
int get(int i) {
int r = 0;
for (; i > 0; i -= i & -i) {
r += f[i];
}
return r;
}
int get(int l, int r) {
return get(r) - get(l - 1);
}
};
int n, m;
int h[N];
fenwick_tree ft;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> h[i];
if (i >= 2) {
ft.upd(min(h[i - 1], h[i]), max(h[i - 1], h[i]), 1);
}
}
while (m--) {
int t;
cin >> t;
if (t == 1) {
int pos, val;
cin >> pos >> val;
if (pos > 1) {
ft.upd(min(h[pos - 1], h[pos]), max(h[pos - 1], h[pos]), -1);
}
if (pos < n) {
ft.upd(min(h[pos + 1], h[pos]), max(h[pos + 1], h[pos]), -1);
}
h[pos] = val;
if (pos > 1) {
ft.upd(min(h[pos - 1], h[pos]), max(h[pos - 1], h[pos]), +1);
}
if (pos < n) {
ft.upd(min(h[pos + 1], h[pos]), max(h[pos + 1], h[pos]), +1);
}
} else if (t == 2) {
int H;
cin >> H;
cout << ft.get(H) << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
5012 KB |
Output is correct |
3 |
Correct |
1 ms |
4764 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4764 KB |
Output is correct |
6 |
Correct |
1 ms |
4764 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
5012 KB |
Output is correct |
3 |
Correct |
1 ms |
4764 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4764 KB |
Output is correct |
6 |
Correct |
1 ms |
4764 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
24 ms |
5500 KB |
Output is correct |
9 |
Correct |
28 ms |
6856 KB |
Output is correct |
10 |
Correct |
27 ms |
6748 KB |
Output is correct |
11 |
Correct |
23 ms |
5468 KB |
Output is correct |
12 |
Correct |
27 ms |
6480 KB |
Output is correct |
13 |
Correct |
26 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
5012 KB |
Output is correct |
3 |
Correct |
1 ms |
4764 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4764 KB |
Output is correct |
6 |
Correct |
1 ms |
4764 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
24 ms |
5500 KB |
Output is correct |
9 |
Correct |
28 ms |
6856 KB |
Output is correct |
10 |
Correct |
27 ms |
6748 KB |
Output is correct |
11 |
Correct |
23 ms |
5468 KB |
Output is correct |
12 |
Correct |
27 ms |
6480 KB |
Output is correct |
13 |
Correct |
26 ms |
6748 KB |
Output is correct |
14 |
Correct |
41 ms |
6748 KB |
Output is correct |
15 |
Correct |
40 ms |
6736 KB |
Output is correct |
16 |
Correct |
40 ms |
6952 KB |
Output is correct |
17 |
Correct |
40 ms |
6740 KB |
Output is correct |
18 |
Correct |
41 ms |
6900 KB |
Output is correct |