forked from atcoder/ac-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegtree_practice.cpp
46 lines (38 loc) · 934 Bytes
/
segtree_practice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <atcoder/segtree>
#include <cstdio>
#include <vector>
using namespace std;
using namespace atcoder;
int op(int a, int b) { return max(a, b); }
int e() { return -1; }
int target;
bool f(int v) { return v < target; }
int main() {
int n, q;
scanf("%d %d", &n, &q);
vector<int> a(n);
for (int i = 0; i < n; i++) {
scanf("%d", &(a[i]));
}
segtree<int, op, e> seg(a);
for (int i = 0; i < q; i++) {
int t;
scanf("%d", &t);
if (t == 1) {
int x, v;
scanf("%d %d", &x, &v);
x--;
seg.set(x, v);
} else if (t == 2) {
int l, r;
scanf("%d %d", &l, &r);
l--;
printf("%d\n", seg.prod(l, r));
} else if (t == 3) {
int p;
scanf("%d %d", &p, &target);
p--;
printf("%d\n", seg.max_right<f>(p) + 1);
}
}
}