-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSegmentPoint.cpp
More file actions
56 lines (48 loc) · 879 Bytes
/
TreeSegmentPoint.cpp
File metadata and controls
56 lines (48 loc) · 879 Bytes
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
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define lc (v << 1)
#define rc (v << 1 | 1)
const int N = 3e5, NT = N + 2;
const int NTREE = 524288 * 2 + 2;
long long T[NTREE], A[NT];
int ntree = 1;
void build(int n) {
while (ntree < n)
ntree <<= 1;
for (int i = 1; i <= n; i++)
T[i + ntree - 1] = A[i];
for (int v = ntree - 1; v >= 1; v--)
T[v] = max(T[lc], T[rc]);
}
long long query(int v) {
v += ntree - 1;
long long ans = 0;
while (v > 0) {
ans = max(ans, T[v]);
v >>= 1;
}
return ans;
}
void update(int l, int r, int val) {
l += ntree - 1;
r += ntree - 1;
if (l == r) {
T[l] = val;
return;
}
T[l] = val;
T[r] = val;
while (r - l > 1) {
if (!(l & 1))
T[l + 1]++;
if (r & 1)
T[r - 1]++;
l >>= 1;
r >>= 1;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
return 0;
}