各种错误都尝试过了,最终是没有考虑多组数据
#include<iostream> #include<queue> #include<algorithm> #include<cstdio> #include<cstring> #define size 600100 using namespace std; int sum[size],ret =0; void buildtree(int rt,int L,int R) { if(L==R) { scanf("%d",&sum[rt]); getchar(); return ; } int mid = (L+R)/2; buildtree(rt*2,L,mid); buildtree(rt*2+1,mid+1,R); if(sum[rt*2]>sum[rt*2+1])sum[rt] = sum[rt*2]; else sum[rt] = sum[rt*2+1]; } void update(int x,int y,int L,int R,int rt) { //cout<<"fewffew"; if(L==R) { sum[rt] = y; return ; } int mid = (L+R)/2; if(x<=mid) update(x,y,L,mid,rt*2); else update(x,y,mid+1,R,rt*2+1); if(sum[rt*2]>sum[rt*2+1])sum[rt] = sum[rt*2]; else sum[rt] = sum[rt*2+1]; } int query(int rt,int l,int r,int L,int R) { if(L<=l&&r<=R) { return sum[rt]; } int mid = (l+r)/2; if(L<=mid){ int z = query(rt*2,l,mid,L,R); ret = ret>z?ret:z; } if(R>mid){ int z =query(rt*2+1,mid+1,r,L,R); ret = ret>z?ret:z; } return ret; } int main() { int n,m,a,b; while(scanf("%d%d",&n,&m)!=EOF){ buildtree(1,1,n); while(m--) { ret =0; char s[2]; scanf("%s",s); scanf("%d%d",&a,&b); getchar(); if(s[0]=='Q') { printf("%d ",query(1,1,n,a,b)); } else { update(a,b,1,n,1); } } } return 0; }