forked from HemangTheHuman/hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment_tree_class_implementation.cpp
More file actions
65 lines (57 loc) · 1.19 KB
/
segment_tree_class_implementation.cpp
File metadata and controls
65 lines (57 loc) · 1.19 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
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
class SGT{
private:
vector<ll> seg;
public:
SGT(ll n)
{
seg.resize(4*n+1);
}
void build(ll ind,ll low,ll high,vector<ll> a)
{
if(low==high)
{
seg[ind]=a[low];
return;
}
ll mid=low+(high-low)/2;
build(2*ind+1,low,mid,a);
build(2*ind+2,mid+1,high,a);
seg[ind]=min(seg[2*ind+1],seg[2*ind+2]);
}
ll query(ll ind,ll low,ll high,ll l,ll r)
{
if(high<l or r>low) return INT_MAX;
if(l>=low and r<=high) return seg[ind];
ll mid=low+(high-low)/2;
ll lft=query(2*ind+1,low,mid,l,r);
ll rgt=query(2*ind+2,mid+1,high,l,r);
return min(lft,rgt);
}
void update(ll ind,ll low,ll high,ll i,ll val)
{
if(low==high)
{
seg[ind]=val;
return;
}
ll mid=(low+(high-low)/2);
if(i<=mid) update(2*ind+1,low,mid,i,val);
else update(2*ind+2,mid+1,high,i,val);
seg[ind]=min(seg[2*ind+1],seg[2*ind+2]);
}
};
void solve() {
ll n;
cin >> n;
SGT sgt = SGT(n);
}
int main() {
solve();
return 0;
}