The interval is the most, the data range is also very small, because only the line segment tree, so set up a line segment tree template =.=
Sample Input
3
1
100
1
1 1
5
1 2 3) 4 5
5
1 2
1 3
2 4
3 4
3 5
3
1 999999 1
4
1 1
1 2
2 3
3 3
Sample Output
100
2
3
4
4
5
1
999999
999999
1
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <cmath>6# include <queue>7# define LLLong Long8 using namespacestd;9 Ten Const intMAXN =1010; One A intmax[maxn<<2] ;//4 times times the knot. - - voidPushup (intRt//Update to parent node the { -MAX[RT] = max (MAX[RT *2], Max[rt *2+1] );//RT is the current node. - } - + voidBuildintLintRintRt//Building a segment tree - { + if(L = =R) A { atscanf"%d", &Max[rt]); - return ; - } - intm = (L + r)/2 ; -Build (L, M, RT *2) ; -Build (M +1, R, RT *2+1) ; in pushup (RT); - } to + - intQueryintJ JintRintLintRintRt//interval to find the maximum value the { * if(l <= l && R <=R) $ returnMax[rt];Panax Notoginseng intm = (L + r)/2 ; - intRET =0 ; the if(L <=m) +RET = max (ret, query (L, R, L, M, RT *2) ) ; A if(R >m) theRET = max (ret, query (L, R, M +1, R, RT *2+1) ); + returnret; - } $ $ intMain () - { - //freopen ("In.txt", "R", stdin); the intN, M; - intT;Wuyiscanf"%d", &T); the while(t--) - { Wuscanf"%d", &n); -Build1N1) ; Aboutscanf"%d", &m); $ while(m--) - { - intA, B; -scanf"%d%d", &a, &b); Aprintf"%d\n", query (A, B,1N1)) ; + } the } - $ return 0 ; the}View Code
Hdu 5443 (2015 Changchun net race g question to find interval maximum)