标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 51036 Accepted Submission(s): 20011
#include<cstdio> #include<cstring> #include<utility> #include<queue> using namespace std; #define N 200002 int t,n,x,y,m; int tre[4*N]; char s[10]; void build(int num,int le,int ri) { if(le==ri) { scanf("%d",&tre[num]); return ; } int mid=(le+ri)/2; build(num*2,le,mid); build(num*2+1,mid+1,ri); tre[num]=max(tre[num*2],tre[num*2+1]); } void update(int num,int le,int ri,int x,int y) { if(le==ri) { tre[num]=y; return; } int mid=(le+ri)/2; if(x<=mid) update(num*2,le,mid,x,y);//更新左边的 else update(num*2+1,mid+1,ri,x,y);//更新右边的 tre[num]=max(tre[num*2],tre[num*2+1]); } int query(int num,int le,int ri,int x,int y) { if(x<=le&&y>=ri) return tre[num]; int mid=(le+ri)/2; int ans=0; if(x<=mid) ans=max(ans,query(num*2,le,mid,x,y)); if(y>mid) ans=max(ans,query(num*2+1,mid+1,ri,x,y)); return ans; } int main() { // scanf("%d",&t); //int ha=0; // while(t--) // { while(~scanf("%d%d",&n,&m)) { build(1,1,n); //printf("Case %d:\n",++ha); while(m--) { scanf("%s",s); if(s[0]==‘U‘) { scanf("%d%d",&x,&y); update(1,1,n,x,y); } if(s[0]==‘Q‘) { scanf("%d%d",&x,&y); printf("%d\n",query(1,1,n,x,y)); } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/ZP-Better/p/4722421.html