Topic Connection: http://acm.hdu.edu.cn/showproblem.php?pid=1754
Segment tree feature: Update: Single point replace query: Interval max
Template Bare Title ...
#pragmaComment (linker, "/stack:102400000,102400000")#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<stack>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 200010#defineFILL (A, B) (Memset (A,b,sizeof (a)))#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1using namespacestd;intmx[n<<2];intA[n];voidPushup (intRT) {Mx[rt]=max (mx[rt<<1],mx[rt<<1|1]);}voidBuildintLintRintRT) { if(l==R) {Mx[rt]=A[l]; return; } intM= (l+r) >>1; Build (Lson); Build (Rson); Pushup (RT);}voidUpdateintPosintNumintLintRintRT) { if(l==R) {Mx[rt]=num; return; } intM= (l+r) >>1; if(pos<=m) update (Pos,num,lson); if(m<POS) Update (Pos,num,rson); Pushup (RT);}intQueryintLintRintLintRintRT) { if(l<=l&&r<=R) {returnMx[rt]; } intM= (l+r) >>1; intres=0; if(l<=m) res=Max (Res,query (L,r,lson)); if(M<r) res=Max (Res,query (L,r,rson)); returnRes;}intMain () {intn,m; Charop[Ten]; while(SCANF ("%d%d", &n,&m) >0) { for(intI=1; i<=n;i++) scanf ("%d",&A[i]); Build (1N1); while(m--) { intb; scanf ("%s%d%d",op,&a,&b); if(op[0]=='Q') printf ("%d\n", query (A, B,1N1)); ElseUpdate (A, B,1N1); } }}
View Code
hdu1754 (segment tree)