Q number
Q Interval Maximum-interval minimum value
1 //#pragma COMMENT (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <sstream>6#include <string>7#include <algorithm>8#include <list>9#include <map>Ten#include <vector> One#include <queue> A#include <stack> -#include <cmath> -#include <cstdlib> the //#include <conio.h> - using namespacestd; - #defineCLC (A, B) memset (A,b,sizeof (a)) - #defineINF 0x3f3f3f3f + #defineLson l,mid,rt<<1 - #defineRson mid+1,r,rt<<1|1 + Const intn=200010; A Const intMOD = 1e9+7; at #defineLL Long Long - Double ConstPI = ACOs (-1); - voidfre () { -Freopen ("In.txt","R", stdin); - } - //Inline int R () { in //int X=0,f=1;char Ch=getchar (); - //While (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} to //while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f; + // } - intA[n]; the intMin,max; * structedge{ $ intL,r;Panax Notoginseng intMinx,maxx; -}e[4*N]; the + voidPushup (intRT) { AE[rt].minx=min (e[rt<<1].minx,e[rt<<1|1].minx); theE[rt].maxx=max (e[rt<<1].maxx,e[rt<<1|1].maxx); + } - $ voidBuildintLintRintRT) { $E[rt].l=l; -E[rt].r=R; - if(l==R) { thee[rt].minx=e[rt].maxx=A[l]; - return;Wuyi } the intMid= (l+r) >>1; - build (Lson); Wu build (Rson); - pushup (RT); About } $ - voidQueryintLintRintRtintLintR) { - if(e[rt].maxx<=max&&e[rt].minx>=min)return; - if(l<=l&&r>=R) { Amin=min (e[rt].minx,min); +max=Max (E[rt].maxx,max); the return; - } $ intMid= (l+r) >>1; the if(l<=mid) query (l,mid,rt<<1, l,r); the if(r>mid) query (mid+1,r,rt<<1|1, l,r); the //if (r<=mid) query (lson,l,r); the //else if (l>mid) query (rson,l,r); - //else{ in //query (lson,l,r); the //query (rson,l,r); the // } About } the the intMain () { the //fre (); + intn,q; -scanf"%d%d",&n,&q); the for(intI=1; i<=n;i++){Bayiscanf"%d",&a[i]); the } theBuild1N1); - while(q--){ - intL,r; thescanf"%d%d",&l,&R); themin=inf,max=-inf; the //cout<< "!" <<endl; the //getch (); -Query1N1, l,r); theprintf"%d\n", max-Min); the } the return 0;94}
POJ3264 Balanced lineup segment tree interval maximum minimum value