-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment_tree.cpp
More file actions
50 lines (42 loc) · 866 Bytes
/
Copy pathsegment_tree.cpp
File metadata and controls
50 lines (42 loc) · 866 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
#include<bits/stdc++.h>
using namespace std;
#define MX 1000000
int T[4*MX], a[MX];
void up(int p, int l, int h, int x, int vl)
{
if(l==h)
{
T[p]=vl; return;
}
int m=(l+h)/2;
if(x<=m) up(2*p, l, m, x, vl);
else up(2*p+1, m+1, h, x, vl);
T[p]=max(T[2*p],T[2*p+1]);
}
int Q(int p, int l, int h, int x, int y)
{
if(l>y || h<x) return -INT_MAX;
if(l>=x && h<=y) return T[p];
int m=(l+h)/2;
return max(Q(2*p, l, m, x, y),Q(2*p+1, m+1, h, x, y));
}
void B(int l, int h, int p)
{
if(l==h)
{
T[p]=a[l]; return;
}
int m=(l+h)/2;
B(2*p, l, m);
B(2*p+1, m+1, h);
T[p]=max(T[2*p], T[2*p+1]);
}
int main()
{
int n=10;
B(1, 1, n);
up(1, 1, n, x, vl);
int mx=Q(1, 1, n, 1, n);
cout<<mx<<endl;
return 0;
}