#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 200005, INF = 1000000007;
int n, q, a[MXN], b[MXN];
pii operator+(pii a, pii b) {
return mp(a.fs + b.fs, a.sc + b.sc);
}
struct PSMG {
#define mid ((l + r) >> 1)
int L[MXN * 60], R[MXN * 60], nc;
pii val[MXN * 60];
void init() {
nc = 2;
}
int modify(int id, int l, int r, int p, pii v) {
if (id == 0) id = nc++;
// debug(id, l, r, p);
if (l + 1 == r) {
val[id] = val[id] + v;
return id;
}
if (p < mid) L[id] = modify(L[id], l, mid, p, v);
else R[id] = modify(R[id], mid, r, p, v);
val[id] = val[L[id]] + val[R[id]];
return id;
}
pii query(int id, int l, int r, int _l, int _r) {
if (_r <= l || r <= _l) return mp(0, 0);
if (_l <= l && r <= _r) return val[id];
return query(L[id], l, mid, _l, _r) + query(R[id], mid, r, _l, _r);
}
#undef mid
} smg;
void PRE() {
smg.init();
FOR(i, 0, n - 1) b[i] = min(a[i], a[i + 1]);
FOR(i, 0, n) smg.modify(1, 0, INF, a[i], mp(1, 0));
FOR(i, 0, n - 1) smg.modify(1, 0, INF, b[i], mp(0, 1));
}
void MODIFY(int p, int v) {
smg.modify(1, 0, INF, a[p], mp(-1, 0));
if (p) smg.modify(1, 0, INF, b[p - 1], mp(0, -1));
if (p != n - 1) smg.modify(1, 0, INF, b[p], mp(0, -1));
a[p] = v;
if (p) b[p - 1] = min(a[p - 1], a[p]);
if (p != n - 1) b[p] = min(a[p], a[p + 1]);
smg.modify(1, 0, INF, a[p], mp(1, 0));
if (p) smg.modify(1, 0, INF, b[p - 1], mp(0, 1));
if (p != n - 1) smg.modify(1, 0, INF, b[p], mp(0, 1));
}
int QUERY(int bnd) {
auto [x, y] = smg.query(1, 0, INF, bnd, INF);
return x - y;
}
void miku() {
int t, x, y;
cin >> n >> q;
FOR(i, 0, n) cin >> a[i];
PRE();
while (q--) {
cin >> t;
if (t == 1) {
cin >> x;
cout << QUERY(x) << '\n';
} else {
cin >> x >> y;
MODIFY(--x, y);
}
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94544 KB |
Output is correct |
2 |
Correct |
39 ms |
94288 KB |
Output is correct |
3 |
Correct |
51 ms |
94288 KB |
Output is correct |
4 |
Correct |
41 ms |
94548 KB |
Output is correct |
5 |
Correct |
40 ms |
94548 KB |
Output is correct |
6 |
Correct |
40 ms |
94544 KB |
Output is correct |
7 |
Correct |
40 ms |
94756 KB |
Output is correct |
8 |
Correct |
42 ms |
94544 KB |
Output is correct |
9 |
Correct |
43 ms |
94740 KB |
Output is correct |
10 |
Correct |
48 ms |
94676 KB |
Output is correct |
11 |
Correct |
43 ms |
94804 KB |
Output is correct |
12 |
Correct |
43 ms |
94800 KB |
Output is correct |
13 |
Correct |
46 ms |
94896 KB |
Output is correct |
14 |
Correct |
44 ms |
94700 KB |
Output is correct |
15 |
Correct |
46 ms |
94676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94292 KB |
Output is correct |
2 |
Correct |
47 ms |
94288 KB |
Output is correct |
3 |
Correct |
42 ms |
94680 KB |
Output is correct |
4 |
Correct |
54 ms |
96596 KB |
Output is correct |
5 |
Correct |
78 ms |
99924 KB |
Output is correct |
6 |
Correct |
94 ms |
100896 KB |
Output is correct |
7 |
Correct |
124 ms |
106064 KB |
Output is correct |
8 |
Correct |
143 ms |
107764 KB |
Output is correct |
9 |
Correct |
259 ms |
112468 KB |
Output is correct |
10 |
Correct |
283 ms |
119376 KB |
Output is correct |
11 |
Correct |
282 ms |
117984 KB |
Output is correct |
12 |
Correct |
338 ms |
121644 KB |
Output is correct |
13 |
Correct |
364 ms |
122192 KB |
Output is correct |
14 |
Correct |
332 ms |
121424 KB |
Output is correct |
15 |
Correct |
338 ms |
121416 KB |
Output is correct |
16 |
Correct |
350 ms |
122232 KB |
Output is correct |
17 |
Correct |
380 ms |
122192 KB |
Output is correct |
18 |
Correct |
349 ms |
122280 KB |
Output is correct |
19 |
Correct |
338 ms |
122320 KB |
Output is correct |
20 |
Correct |
365 ms |
122192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94544 KB |
Output is correct |
2 |
Correct |
39 ms |
94288 KB |
Output is correct |
3 |
Correct |
51 ms |
94288 KB |
Output is correct |
4 |
Correct |
41 ms |
94548 KB |
Output is correct |
5 |
Correct |
40 ms |
94548 KB |
Output is correct |
6 |
Correct |
40 ms |
94544 KB |
Output is correct |
7 |
Correct |
40 ms |
94756 KB |
Output is correct |
8 |
Correct |
42 ms |
94544 KB |
Output is correct |
9 |
Correct |
43 ms |
94740 KB |
Output is correct |
10 |
Correct |
48 ms |
94676 KB |
Output is correct |
11 |
Correct |
43 ms |
94804 KB |
Output is correct |
12 |
Correct |
43 ms |
94800 KB |
Output is correct |
13 |
Correct |
46 ms |
94896 KB |
Output is correct |
14 |
Correct |
44 ms |
94700 KB |
Output is correct |
15 |
Correct |
46 ms |
94676 KB |
Output is correct |
16 |
Correct |
40 ms |
94292 KB |
Output is correct |
17 |
Correct |
47 ms |
94288 KB |
Output is correct |
18 |
Correct |
42 ms |
94680 KB |
Output is correct |
19 |
Correct |
54 ms |
96596 KB |
Output is correct |
20 |
Correct |
78 ms |
99924 KB |
Output is correct |
21 |
Correct |
94 ms |
100896 KB |
Output is correct |
22 |
Correct |
124 ms |
106064 KB |
Output is correct |
23 |
Correct |
143 ms |
107764 KB |
Output is correct |
24 |
Correct |
259 ms |
112468 KB |
Output is correct |
25 |
Correct |
283 ms |
119376 KB |
Output is correct |
26 |
Correct |
282 ms |
117984 KB |
Output is correct |
27 |
Correct |
338 ms |
121644 KB |
Output is correct |
28 |
Correct |
364 ms |
122192 KB |
Output is correct |
29 |
Correct |
332 ms |
121424 KB |
Output is correct |
30 |
Correct |
338 ms |
121416 KB |
Output is correct |
31 |
Correct |
350 ms |
122232 KB |
Output is correct |
32 |
Correct |
380 ms |
122192 KB |
Output is correct |
33 |
Correct |
349 ms |
122280 KB |
Output is correct |
34 |
Correct |
338 ms |
122320 KB |
Output is correct |
35 |
Correct |
365 ms |
122192 KB |
Output is correct |
36 |
Correct |
40 ms |
94288 KB |
Output is correct |
37 |
Correct |
45 ms |
94472 KB |
Output is correct |
38 |
Correct |
44 ms |
94904 KB |
Output is correct |
39 |
Correct |
67 ms |
98132 KB |
Output is correct |
40 |
Correct |
89 ms |
100176 KB |
Output is correct |
41 |
Correct |
134 ms |
103760 KB |
Output is correct |
42 |
Correct |
192 ms |
108684 KB |
Output is correct |
43 |
Correct |
247 ms |
112208 KB |
Output is correct |
44 |
Correct |
532 ms |
126956 KB |
Output is correct |
45 |
Correct |
372 ms |
120916 KB |
Output is correct |
46 |
Correct |
437 ms |
123268 KB |
Output is correct |
47 |
Correct |
592 ms |
130896 KB |
Output is correct |
48 |
Correct |
608 ms |
130896 KB |
Output is correct |
49 |
Correct |
598 ms |
131156 KB |
Output is correct |
50 |
Correct |
661 ms |
130388 KB |
Output is correct |
51 |
Correct |
657 ms |
131488 KB |
Output is correct |
52 |
Correct |
620 ms |
131412 KB |
Output is correct |
53 |
Correct |
602 ms |
131548 KB |
Output is correct |
54 |
Correct |
566 ms |
131660 KB |
Output is correct |
55 |
Correct |
589 ms |
131152 KB |
Output is correct |