Skip to content

Commit 69b533e

Browse files
authored
Create 1649-DynamicRangeMinQueries.cpp
1 parent 3668741 commit 69b533e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// JAI BAJARANG BALI
2+
3+
// manitianajay45
4+
5+
// give me some sunshine, give me some rain ,give me another chance to grow up once again....
6+
7+
// sab moh maya hai....
8+
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
12+
#define ll long long
13+
14+
15+
// ll st[200005][25];
16+
vector<ll> seg(800005,INT_MAX);
17+
18+
void st(ll i,ll val,ll x,ll l,ll r){
19+
if(r-l==1){
20+
seg[x]=val;
21+
return ;
22+
}
23+
ll mid=(l+r)/2;
24+
if(i<mid){
25+
st(i,val,2*x+1,l,mid);
26+
}else{
27+
st(i,val,2*x+2,mid,r);
28+
}
29+
seg[x]=min(seg[2*x+1],seg[2*x+2]);
30+
}
31+
32+
33+
ll sum(ll l,ll r,ll x,ll lf,ll rf){
34+
if(lf>=l && r>=rf){
35+
return seg[x];
36+
}else if(lf>=r || rf<=l){
37+
return INT_MAX;
38+
}
39+
ll mid=(lf+rf)/2;
40+
41+
return min(sum(l,r,2*x+1,lf,mid),sum(l,r,2*x+2,mid,rf));
42+
43+
}
44+
45+
int main()
46+
{
47+
48+
ios_base::sync_with_stdio(false);
49+
50+
cin.tie(NULL);
51+
52+
53+
ll n,q;
54+
cin>>n>>q;
55+
// cout<<"YES"<<endl;
56+
57+
for(ll i=0;i<n;i++)
58+
{
59+
ll x;
60+
cin>>x;
61+
st(i,x,0,0,n);
62+
}
63+
// cout<<"YES"<<endl;
64+
65+
while(q--){
66+
ll tp;
67+
cin>>tp;
68+
if(tp==1){
69+
ll i,val;
70+
cin>>i>>val;
71+
i--;
72+
st(i,val,0,0,n);
73+
continue;
74+
}
75+
ll l,r;
76+
cin>>l>>r;
77+
l--;
78+
// r--;
79+
ll ans=sum(l,r,0,0,n);
80+
cout<<ans<<endl;
81+
82+
}
83+
return 0;
84+
}

0 commit comments

Comments
 (0)