-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegTree.CPP
More file actions
72 lines (59 loc) · 1.95 KB
/
SegTree.CPP
File metadata and controls
72 lines (59 loc) · 1.95 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define ins insert
#define sz(x) (int)x.size()
#define dbg(x) cout << x << "\n";
const int N = 4e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
int dx[9] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
int dy[9] = {0, 0, 0, 1, -1, 1, -1, 1, -1};
using namespace std;
struct SegmentTree{
vector <int> t;
void Initialize (int n) {t.assign(4 * n, 0); }
void Update (int idx, int val, int v, int tl, int tr){
if(tl == tr) t[v] = val;
else{
int tm = (tl + tr) >> 1;
if(idx <= tm) Update(idx, val, 2 * v + 1, tl, tm);
else Update(idx, val, 2 * v + 2, tm + 1, tr);
t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}
}
int Max (int l, int r, int v, int tl, int tr){
if(tl == l && tr == r) return t[v];
else{
int tm = (tl + tr) >> 1;
if(r <= tm) return Max(l, r, 2 * v + 1, tl, tm);
else if(l > tm) return Max(l, r, 2 * v + 2, tm + 1, tr);
else return max(Max(l, tm, 2 * v + 1, tl, tm), Max(tm + 1, r, 2 * v + 2, tm + 1, tr));
}
}
};
void TestCase (){
int n, m;
cin >> n >> m;
struct SegmentTree sgmt;
sgmt.Initialize();
}
int main(){
IOS;
int T = 1;
// cin >> T;
while(T--){
TestCase();
cout << "\n";
}
return 0;
}