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
| #include<iostream> #include<cstdio> #include<iomanip> #include<cstring> #include<vector> #include<map> #include<queue> #include<set> #include<algorithm> #include<cmath> using namespace std; const int MAXN=2e5+10; int score[MAXN],tree[MAXN<<2]; int N,M; void Build_tree(int o,int L,int R){ if(L==R){ tree[o]=score[L]; return ; } int mid=L+((R-L)>>1); Build_tree(o<<1,L,mid); Build_tree(o<<1|1,mid+1,R); tree[o]=max(tree[o<<1],tree[o<<1|1]); } void Update(int o,int L,int R,int idx,int val){ if(L==R){ tree[o]=val; return ; } int mid=L+((R-L)>>1); if(idx<=mid) Update(o<<1,L,mid,idx,val); else Update(o<<1|1,mid+1,R,idx,val); tree[o]=max(tree[o<<1],tree[o<<1|1]); } int Query(int o,int L,int R,int ql,int qr){ if(ql<=L&&qr>=R) return tree[o]; int mid=L+((R-L)>>1); int ret=0; if(ql<=mid) ret=max(ret,Query(o<<1,L,mid,ql,qr)); if(qr>mid) ret=max(ret,Query(o<<1|1,mid+1,R,ql,qr)); return ret; } int main(){ while(~scanf("%d%d",&N,&M)){ for(int i=1;i<=N;i++){ scanf("%d",&score[i]); } Build_tree(1,1,N); char order; int l,r; while(M--){ scanf("%s%d%d",&order,&l,&r); if(order=='Q'){ printf("%d\n",Query(1,1,N,l,r)); }else if(order=='U'){ Update(1,1,N,l,r); } } } return 0; }
|