标签:hint better others key ssi 比较 lan 分数 can
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 76334 Accepted Submission(s):
29413
#include<cstdio> const int N=200005; char a[10]; int p,q; int sum[N*3]; int read(){ int x=0,f=1;char c=getchar(); while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c<=‘9‘&&c>=‘0‘){x=x*10+c-‘0‘;c=getchar();}return x*f;} int max(int x,int y) { if(x>y)return x; return y; } void update(int rt) { sum[rt]=max(sum[rt<<1],sum[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r){ sum[rt]=read(); return ; } int mid=(l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); update(rt); } void modify(int l,int r,int rt) { if(r==l){ sum[rt]=q;return; } int mid=(l+r)>>1; if(mid>=p) modify(l,mid,rt<<1); else modify(mid+1,r,rt<<1|1); update(rt); } int query(int l,int r,int rt,int nowl,int nowr) { if(nowl<=l&&nowr>=r) { return sum[rt]; } int m=(r+l)>>1; int ans=0; if(nowl<=m) ans=max(ans,query(l,m,rt<<1,nowl,nowr)); if(nowr>m) ans=max(ans,query(m+1,r,rt<<1|1,nowl,nowr)); return ans; } int main() { int n,m; while(scanf("%d%d",&n,&m)==2) { build(1,n,1); while(m--) { scanf("%s",a); p=read();q=read(); if(a[0]==‘U‘)modify(1,n,1); else if(a[0]==‘Q‘)printf("%d\n",query(1,n,1,p,q)); } } return 0; }
标签:hint better others key ssi 比较 lan 分数 can
原文地址:http://www.cnblogs.com/sssy/p/7060099.html