#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int A = 1e9;
struct ST{
struct node{
int s;
node *l, *r;
node(){
s = 0;
l = r = 0;
}
};
node *rt;
void init(){
rt = new node();
}
void upd(node *v, int tl, int tr, int& p, int& x){
if (tl == tr){
v -> s += x;
return;
}
int tm = (tl + tr) / 2;
if (p <= tm){
if (!(v -> l)) v -> l = new node();
upd(v -> l, tl, tm, p, x);
}
else {
if (!(v -> r)) v -> r = new node();
upd(v -> r, tm + 1, tr, p, x);
}
v -> s = 0;
if (v -> l) v -> s += v -> l -> s;
if (v -> r) v -> s += v -> r -> s;
}
void upd(int p, int x){
if (p > A) return;
upd(rt, 1, A, p, x);
}
void upd(int l, int r, int x){
upd(l, x);
upd(r + 1, -x);
}
int get(node *v, int tl, int tr, int l, int r){
if (l > tr || r < tl) return 0;
if (l <= tl && tr <= r) return v -> s;
int tm = (tl + tr) / 2, out = 0;
if (v -> l) out += get(v -> l, tl, tm, l, r);
if (v -> r) out += get(v -> r, tm + 1, tr, l, r);
return out;
}
int get(int v){
return get(rt, 1, A, 1, v);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q; cin>>n>>q;
vector<int> a(n + 2), x(n + 2);
for (int i = 1; i <= n; i++){
cin>>a[i];
}
ST T; T.init();
auto add = [&](int v, int t){
int k = max(x[v - 1], x[v + 1]);
if (k < x[v]){
T.upd(k + 1, x[v], t);
}
k = min({x[v - 1], x[v], x[v + 1]});
if (1 <= k){
T.upd(1, k, -t);
}
};
for (int i = 1; i <= n; i++){
x[i] = a[i];
add(i, 1);
}
while (q--){
int type; cin>>type;
if (type == 1){
int f; cin>>f;
cout<<T.get(f)<<"\n";
}
else {
int f, y; cin>>f>>y;
add(f, -1);
x[f] = y;
add(f, 1);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
984 KB |
Output is correct |
7 |
Correct |
4 ms |
1360 KB |
Output is correct |
8 |
Correct |
4 ms |
1360 KB |
Output is correct |
9 |
Correct |
3 ms |
1616 KB |
Output is correct |
10 |
Correct |
4 ms |
1872 KB |
Output is correct |
11 |
Correct |
4 ms |
1872 KB |
Output is correct |
12 |
Correct |
5 ms |
1872 KB |
Output is correct |
13 |
Correct |
5 ms |
1872 KB |
Output is correct |
14 |
Correct |
7 ms |
1896 KB |
Output is correct |
15 |
Correct |
4 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
5 ms |
1616 KB |
Output is correct |
4 |
Correct |
17 ms |
6480 KB |
Output is correct |
5 |
Correct |
43 ms |
16748 KB |
Output is correct |
6 |
Correct |
57 ms |
18684 KB |
Output is correct |
7 |
Correct |
93 ms |
33352 KB |
Output is correct |
8 |
Correct |
113 ms |
37880 KB |
Output is correct |
9 |
Correct |
181 ms |
49396 KB |
Output is correct |
10 |
Correct |
230 ms |
73448 KB |
Output is correct |
11 |
Correct |
254 ms |
66340 KB |
Output is correct |
12 |
Correct |
296 ms |
76320 KB |
Output is correct |
13 |
Correct |
297 ms |
78208 KB |
Output is correct |
14 |
Correct |
298 ms |
75848 KB |
Output is correct |
15 |
Correct |
325 ms |
76332 KB |
Output is correct |
16 |
Correct |
302 ms |
78664 KB |
Output is correct |
17 |
Correct |
317 ms |
78664 KB |
Output is correct |
18 |
Correct |
310 ms |
78920 KB |
Output is correct |
19 |
Correct |
312 ms |
79056 KB |
Output is correct |
20 |
Correct |
295 ms |
77896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
984 KB |
Output is correct |
7 |
Correct |
4 ms |
1360 KB |
Output is correct |
8 |
Correct |
4 ms |
1360 KB |
Output is correct |
9 |
Correct |
3 ms |
1616 KB |
Output is correct |
10 |
Correct |
4 ms |
1872 KB |
Output is correct |
11 |
Correct |
4 ms |
1872 KB |
Output is correct |
12 |
Correct |
5 ms |
1872 KB |
Output is correct |
13 |
Correct |
5 ms |
1872 KB |
Output is correct |
14 |
Correct |
7 ms |
1896 KB |
Output is correct |
15 |
Correct |
4 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
5 ms |
1616 KB |
Output is correct |
19 |
Correct |
17 ms |
6480 KB |
Output is correct |
20 |
Correct |
43 ms |
16748 KB |
Output is correct |
21 |
Correct |
57 ms |
18684 KB |
Output is correct |
22 |
Correct |
93 ms |
33352 KB |
Output is correct |
23 |
Correct |
113 ms |
37880 KB |
Output is correct |
24 |
Correct |
181 ms |
49396 KB |
Output is correct |
25 |
Correct |
230 ms |
73448 KB |
Output is correct |
26 |
Correct |
254 ms |
66340 KB |
Output is correct |
27 |
Correct |
296 ms |
76320 KB |
Output is correct |
28 |
Correct |
297 ms |
78208 KB |
Output is correct |
29 |
Correct |
298 ms |
75848 KB |
Output is correct |
30 |
Correct |
325 ms |
76332 KB |
Output is correct |
31 |
Correct |
302 ms |
78664 KB |
Output is correct |
32 |
Correct |
317 ms |
78664 KB |
Output is correct |
33 |
Correct |
310 ms |
78920 KB |
Output is correct |
34 |
Correct |
312 ms |
79056 KB |
Output is correct |
35 |
Correct |
295 ms |
77896 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
3 ms |
592 KB |
Output is correct |
38 |
Correct |
6 ms |
2416 KB |
Output is correct |
39 |
Correct |
36 ms |
12168 KB |
Output is correct |
40 |
Correct |
78 ms |
18512 KB |
Output is correct |
41 |
Correct |
126 ms |
29472 KB |
Output is correct |
42 |
Correct |
190 ms |
43592 KB |
Output is correct |
43 |
Correct |
224 ms |
54352 KB |
Output is correct |
44 |
Correct |
475 ms |
98684 KB |
Output is correct |
45 |
Correct |
379 ms |
80916 KB |
Output is correct |
46 |
Correct |
399 ms |
87448 KB |
Output is correct |
47 |
Correct |
536 ms |
110332 KB |
Output is correct |
48 |
Correct |
609 ms |
110068 KB |
Output is correct |
49 |
Correct |
557 ms |
111008 KB |
Output is correct |
50 |
Correct |
531 ms |
108360 KB |
Output is correct |
51 |
Correct |
560 ms |
112136 KB |
Output is correct |
52 |
Correct |
601 ms |
111944 KB |
Output is correct |
53 |
Correct |
614 ms |
112024 KB |
Output is correct |
54 |
Correct |
562 ms |
112172 KB |
Output is correct |
55 |
Correct |
505 ms |
110932 KB |
Output is correct |