Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <sstream>
- #include <climits>
- #define N 100000
- using namespace std;
- int n;
- int tree[4*N+1],c[N+1];
- void init(int node,int a,int b){
- if(a==b){
- tree[node]=c[a];
- return;
- }
- init(2*node+1,a,(a+b)/2);
- init(2*node+2,(a+b)/2+1,b);
- tree[node]=min(tree[2*node+1],tree[2*node+2]);
- }
- int query(int node,int a,int b,int p,int q){
- if(q<a || b<p)return INT_MAX;
- if(a>=p && b<=q){
- return tree[node];
- }
- int v1=2*node+1;
- int v2=2*node+2;
- return min(query(v1,a,(a+b)/2,p,q),query(v2,(a+b)/2+1,b,p,q));
- }
- void update(int node,int a,int b,int p,int val){
- if(b<p || p<a)return;
- if(a==b){
- tree[node]=val;
- return;
- }
- update(2*node+1,a,(a+b)/2,p,val);
- update(2*node+2,(a+b)/2+1,b,p,val);
- tree[node]=min(tree[2*node+1],tree[2*node+2]);
- return;
- }
- int main(){
- int n,t,x;
- char s[40];
- scanf("%d%d",&n,&t);
- for(int i=0;i<n;++i){
- scanf("%d",&c[i]);
- }
- init(0,0,n-1);
- gets(s);
- for(int i=0;i<t;++i){
- vector<int>v,aux;
- bool val=0;
- gets(s);
- if(s[0]=='q')val=1;
- for(int i=0;i<strlen(s);++i){
- if(s[i]>='0' && s[i]<='9'){
- }
- else s[i]=' ';
- }
- istringstream in(s);
- while(in>>x){
- v.push_back(x-1);
- }
- if(val){
- printf("%d",query(0,0,n-1,v[0],v[1]));
- puts("");
- }
- else{
- for(int i=0;i<v.size();++i){
- aux.push_back(c[v[i]]);
- }
- for(int i=0;i<v.size()-1;++i){
- c[v[i]]=aux[i+1];
- update(0,0,n-1,v[i],aux[i+1]);
- }
- if(v.size()>=1){
- c[v[v.size()-1]]=aux[0];
- update(0,0,n-1,v[v.size()-1],aux[0]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment