Topic Connection: http://poj.org/problem?id=3264
Test instructions: A given Q (1<=q<=200000) number a1,a2, "", AQ, multiple times for any interval ai-aj the maximum number and the minimum number of the difference.
Segment tree function: Interval to find the most value, O (logn) Complexity of query
#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 50010#defineFILL (A, B) (Memset (A,b,sizeof (a)))#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1using namespacestd;intmx[n<<2],mn[n<<2];voidPushup (intRT) {Mn[rt]=min (mn[rt<<1],mn[rt<<1|1]); MX[RT]=max (mx[rt<<1],mx[rt<<1|1]);}voidBuildintLintRintRT) { if(l==r) {intx; scanf ("%d",&x); MN[RT]=mx[rt]=x; return; } intM= (l+r) >>1; Build (Lson); Build (Rson); Pushup (RT);}intQuerymin (intLintRintLintRintRT) { if(l<=l&&r<=R) {returnMn[rt]; } intM= (l+r) >>1; intres=inf; if(l<=m) res=min (res,querymin (L,r,lson)); if(M<r) res=min (res,querymin (L,r,rson)); returnRes;}intQuerymax (intLintRintLintRintRT) { if(l<=l&&r<=R) {returnMx[rt]; } intM= (l+r) >>1; intres=0; if(l<=m) res=Max (Res,querymax (L,r,lson)); if(M<r) res=Max (Res,querymax (L,r,rson)); returnRes;}intMain () {intn,m; intb; while(SCANF ("%d%d", &n,&m) >0) {Build (1N1); while(m--) {scanf ("%d%d",&a,&b); intTallest=querymax (A, B,1N1); intShortest=querymin (A, B,1N1); printf ("%d\n", tallest-shortest); } }}View Code
poj3264 (best value for segment tree interval)