标签:date 测试的 author bsp div return 模拟 ios --
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 75546 Accepted Submission(s): 29114
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=8e5+5; int dat[N]; int n=1; void init(int n_) { memset(dat,0,sizeof(dat)); n=1; while(n<n_)n<<=1; for(int i=0;i<n_;i++)scanf("%d",&dat[n+i-1]); for(int i=n-2;i>=0;i--)dat[i]=max(dat[i<<1|1],dat[(i<<1)+2]); } void update(int k,int a) { k+=n-1; dat[k]=a; while(k>0) { k=(k-1)/2; dat[k]=max(dat[k<<1|1],dat[(k<<1)+2]); } } int query(int a,int b,int k,int l,int r) { if(a>r||b<l)return 0; if(a<=l&&r<=b)return dat[k]; else { int lv=query(a,b,k<<1|1,l,(l+r)/2); int rv=query(a,b,(k<<1)+2,(l+r)/2+1,r); return max(lv,rv); } } int main() { int M,N; while(~scanf("%d %d",&N,&M)) { init(N); char s; int a,b; while(M--) { getchar(); scanf("%c",&s); if(s==‘Q‘) { scanf("%d %d",&a,&b); printf("%d\n",query(a-1,b-1,0,0,n-1)); } else { scanf("%d %d",&a,&b); update(a-1,b); } } } return 0; }
标签:date 测试的 author bsp div return 模拟 ios --
原文地址:http://www.cnblogs.com/widsom/p/6906169.html