//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
const int maxN = (int) 1e6 + 1e3;
template<typename T>
struct Bit { // [l, r)
vector<T> t;
int sz;
Bit(int n) : t(n + 1), sz(n) {}
void upd(int i, int val) {
for (++i; i <= sz; i += i & -i) {
t[i] += val;
}
}
T get(int x) {
ll ret = 0;
for (; x; x -= x & -x) {
ret += t[x];
}
return ret;
}
T get(int l, int r) {
return get(r) - get(l);
}
};
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
Bit<ll> bit(maxN);
auto add = [&](int l, int r, int v) {
bit.upd(l, v);
bit.upd(r + 1, -v);
};
for (int i = 0; i < n - 1; ++i) {
int l = min(a[i], a[i + 1]), r = max(a[i], a[i + 1]);
add(l, r, 1);
}
while (m--) {
int t;
cin >> t;
if (t == 1) {
int i, v;
cin >> i >> v;
--i;
if (i > 0) {
add(min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1);
add(min(v, a[i - 1]), max(v, a[i - 1]), 1);
}
if (i < n - 1) {
add(min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1);
add(min(v, a[i + 1]), max(v, a[i + 1]), 1);
}
a[i] = v;
} else {
int h;
cin >> h;
cout << bit.get(h + 1) << '\n';
}
}
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8280 KB |
Output is correct |
6 |
Correct |
2 ms |
8264 KB |
Output is correct |
7 |
Correct |
2 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8280 KB |
Output is correct |
6 |
Correct |
2 ms |
8264 KB |
Output is correct |
7 |
Correct |
2 ms |
8284 KB |
Output is correct |
8 |
Correct |
31 ms |
9676 KB |
Output is correct |
9 |
Correct |
34 ms |
10700 KB |
Output is correct |
10 |
Correct |
36 ms |
10744 KB |
Output is correct |
11 |
Correct |
34 ms |
9564 KB |
Output is correct |
12 |
Correct |
31 ms |
10616 KB |
Output is correct |
13 |
Correct |
38 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8284 KB |
Output is correct |
4 |
Correct |
2 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8280 KB |
Output is correct |
6 |
Correct |
2 ms |
8264 KB |
Output is correct |
7 |
Correct |
2 ms |
8284 KB |
Output is correct |
8 |
Correct |
31 ms |
9676 KB |
Output is correct |
9 |
Correct |
34 ms |
10700 KB |
Output is correct |
10 |
Correct |
36 ms |
10744 KB |
Output is correct |
11 |
Correct |
34 ms |
9564 KB |
Output is correct |
12 |
Correct |
31 ms |
10616 KB |
Output is correct |
13 |
Correct |
38 ms |
10584 KB |
Output is correct |
14 |
Correct |
44 ms |
10832 KB |
Output is correct |
15 |
Correct |
52 ms |
10676 KB |
Output is correct |
16 |
Correct |
52 ms |
10836 KB |
Output is correct |
17 |
Correct |
48 ms |
10856 KB |
Output is correct |
18 |
Correct |
60 ms |
10912 KB |
Output is correct |