Hdu 5443 (2015 Changchun net race g question to find interval maximum)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.