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
|
#define pl(x) (x * 2 + 1)
#define pr(x) (x * 2 + 2)
void build(int index, int l, int r) {
if (l == r) {
tree[index] = arr[l];
return;
}
int mid = (l + r) / 2;
build(pl(index), l, mid);
build(pr(index), mid + 1, r);
tree[index] = tree[pl(index)] * tree[pr(index)];
}
void change(int index, int q, int l, int r, int &value) {
if (l == r) {
tree[index] = value;
return;
}
int mid = (l + r) / 2;
if (mid >= q)
change(pl(index), q, l, mid, value);
else
change(pr(index), q, mid + 1, r, value);
tree[index] = tree[pl(index)] * tree[pr(index)];
}
void query(int index, int ql, int qr, int l, int r, int &ans) {
if (ql <= l && r <= qr) {
ans *= tree[index];
return;
}
int mid = (l + r) / 2;
if (ql <= mid) query(pl(index), ql, qr, l, mid, ans);
if (mid < qr) query(pr(index), ql, qr, mid + 1, r, ans);
}
|