Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
- #include<bits/stdc++.h>
- #define MAX 100005
- #define inf 0x7fffffff
- using namespace std;
- int tree_min[5*MAX],A[MAX],x,y,mid;
- void build(int node,int start,int end)
- {
- if(start==end){
- tree_min[node]=A[start];
- }
- else{
- mid=(start+end)/2;
- build(2*node,start,mid);
- build(2*node+1,mid+1,end);
- tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]);
- }
- }
- void update(int node,int start,int end,int idx,int val)
- {
- if(start==end){
- A[idx]=val;
- tree_min[node]=val;
- }
- else{
- mid=(start+end)/2;
- if(start<=idx && idx<=mid){
- update(2*node,start,mid,idx,val);
- }
- else{
- update(2*node+1,mid+1,end,idx,val);
- }
- tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]);
- }
- }
- int query(int node,int start,int end,int l,int r)
- {
- if(r<start || l>end){
- return 100005;
- }
- if(l<=start && r>=end){
- return tree_min[node];
- }
- mid=(start+end)/2;
- int p1=query(2*node,start,mid,l,r);
- int p2=query(2*node+1,mid+1,end,l,r);
- return min(p1,p2);
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- int q,i,n,tree_min;
- char com;
- cin>>n>>q;
- for(i=1;i<=n;i++){
- cin>>A[i];
- }
- // A[0]=inf;
- build(1,1,n);
- while(q--){
- cin>>com>>x>>y;
- if(com=='q'){
- cout<<query(1,1,n,x,y)<<endl;
- }
- else{
- update(1,1,n,x,y);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement