标签:des blog http io ar os sp java for
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40747 Accepted Submission(s): 16159
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<string> #include<algorithm> #include<cmath> #include<queue> #include<vector> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define N 200005 int sum[N<<2],n,m; char opt[5]; void pushup(int rt) { sum[rt]=max(sum[rt<<1],sum[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&sum[rt]); return ; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt); } void update(int p,int sc,int l,int r,int rt) { if(l==r) { sum[rt]=sc; return ; } int m=(l+r)>>1; if(p<=m) update(p,sc,lson); else update(p,sc,rson); pushup(rt); } int query(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R) { return sum[rt]; } int m=(l+r)>>1; int ret=0; if(L<=m) ret=max(ret,query(L,R,lson)); if(R>m) ret=max(ret,query(L,R,rson)); return ret; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { build(1,n,1); for(int i=1;i<=m;i++) { int a,b; scanf("%s",opt); scanf("%d%d",&a,&b); if(opt[0]==‘Q‘) printf("%d\n",query(a,b,1,n,1)); if(opt[0]==‘U‘) update(a,b,1,n,1); } } }
标签:des blog http io ar os sp java for
原文地址:http://www.cnblogs.com/a972290869/p/4101116.html