标签:des style java color os strong 文件 io
5 6 1 2 3 4 5 Q 1 5 U 3 6 Q 3 4 Q 4 5 U 2 9 Q 1 5
5 6 5 9HintHuge input,the C function scanf() will work better than cin
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct Node{ int left,right; int s; }a[800010]; void built(int cur,int x,int y){ a[cur].left=x; a[cur].right=y; if(x==y){ scanf("%d",&a[cur].s); return ; } int mid=(x+y)>>1; built(cur<<1,x,mid); built(cur<<1|1,mid+1,y); a[cur].s=max(a[cur<<1].s,a[cur<<1|1].s); } void insert(int cur,int v,int val){ if(a[cur].left==v && a[cur].right==v){ a[cur].s=val; return ; } int mid=(a[cur].left+a[cur].right)>>1; if(v<=mid) insert(cur<<1,v,val); else insert(cur<<1|1,v,val); a[cur].s=max(a[cur<<1].s,a[cur<<1|1].s); } int query(int cur,int x,int y){ if(a[cur].left==x && a[cur].right==y){ return a[cur].s; } int mid=(a[cur].left+a[cur].right)>>1; if(y<=mid) return query(cur<<1,x,y); else if(x>mid) return query(cur<<1|1,x,y); else return max(query(cur<<1,x,mid),query(cur<<1|1,mid+1,y)); } void output(int cur){ if(a[cur].left==a[cur].right){ cout<<a[cur].s<<' '; return ; } output(cur<<1); output(cur<<1|1); } int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ built(1,1,n); //output(1); //printf("%d %d %d\n",a[1].s,a[1].left,a[1].right); while(m--){ char ch[2]; scanf("%s",&ch); if(ch[0]=='Q'){ int x,y; scanf("%d%d",&x,&y); cout<<query(1,x,y)<<endl; } else{ int v,val; scanf("%d%d",&v,&val); insert(1,v,val); } } } return 0; }
标签:des style java color os strong 文件 io
原文地址:http://blog.csdn.net/my_acm/article/details/38121869