Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40600 Accepted Submission(s): 16106
#include<cstdio> #include<algorithm> using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define clr(x,y) memset(x,y,sizeof(x)) #define lson l,m,rt << 1 #define rson m+1,r,rt << 1|1 const int maxn=201000; int MAX[maxn<<2]; void PushUP(int rt) { MAX[rt]=max(MAX[rt << 1],MAX[rt << 1|1]); } void build(int l,int r,int rt) { int m; if(l==r) { scanf("%d",&MAX[rt]); return; } m=(l+r) >>1 ; build(lson); build(rson); PushUP(rt); } void Updata(int a, int b, int l,int r,int rt) { int m; if(l==r) { MAX[rt]=b; return ; } m=(l+r) >>1 ; if(a<=m) Updata(a,b,lson); else Updata(a,b,rson); PushUP(rt); } int query(int L,int R,int l,int r,int rt) { int m,ret=-0xffff; if(L<=l && r<=R) { return MAX[rt]; } m=(l+r) >>1 ; if(L<=m) ret=max(ret,query(L,R,lson)); if(R>m) ret=max(ret,query(L,R,rson)); return ret; } int main() { int n,m,a,b; while(~scanf("%d%d",&n,&m)) { build(1,n,1); while(m--) { char op[2]; scanf("%s%d%d",op,&a,&b); if(op[0]==‘Q‘) printf("%d\n",query(a,b,1,n,1)); if(op[0]==‘U‘) Updata(a,b,1,n,1); } } return 0; }
原文:http://www.cnblogs.com/sxiszero/p/4076267.html