标签:des style blog color java os io strong
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<cstring> #include<algorithm> using namespace std; int max(int a,int b) { return (a>b?a:b); } int a[200000]; struct Node { int left,right; int t; }node[4*200000]; void MakeTree(int l,int r,int i) { node[i].left=l; node[i].right=r; if(l==r) { node[i].t=a[l]; return ; } int mid=(l+r)/2; MakeTree(l,mid,2*i); MakeTree(mid+1,r,2*i+1); node[i].t=max(node[2*i].t,node[2*i+1].t); } void UpdateTree(int i,int x,int y) { int l=node[i].left; int r=node[i].right; int mid=(l+r)/2; if(x==l&&x==r) { node[i].t=y; return ; } if(x>mid) UpdateTree(2*i+1,x,y); else UpdateTree(2*i,x,y); node[i].t=max(node[2*i].t,node[2*i+1].t); } int QueryTree(int x,int y,int i) { if(node[i].left==x && node[i].right==y) return node[i].t; //if(node[i].left==node[i].right) //return 0; int m=(node[i].left+node[i].right)/2; if(x>m) return QueryTree(x,y,2*i+1); else if(y<=m) return QueryTree(x,y,2*i); else return max(QueryTree(x,m,2*i),QueryTree(m+1,y,2*i+1)); } int main () { int T,n,m; int i,j,x,y; char c[10]; while(~scanf("%d%d",&n,&m)) { for(i=1;i<=n;i++) scanf("%d",&a[i]); MakeTree(1,n,1); getchar(); for(j=1;j<=m;j++) { scanf("%c%d%d",&c[0],&x,&y); getchar(); if(c[0]=='U') UpdateTree(1,x,y); else cout<<QueryTree(x,y,1)<<endl; } } return 0; }
hdu 1754 I Hate It,布布扣,bubuko.com
标签:des style blog color java os io strong
原文地址:http://blog.csdn.net/fyxz1314/article/details/38391019