ACM Changchun Division Registration Questions

Source: Internet
Author: User

Sunday playing the online game, although I do not have anything (┬_┬) feeling the gap is great ... This semester can not play again, learn ACM, strive not to pull the hind legs of teammates. This problem is a line tree of the naked question, and there is nothing good to say, write a question to leave a souvenir.

The water problem

Time limit:1500/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 574 Accepted Submission (s): 460


Problem DescriptionIn Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with< Span id= "mathjax-span-4" class= "Mi" >a1 , a 2, A3 , An Representing the size of the water source. Given a set of queries each containing2IntegersLand R, please find the biggest water source between al and aR .

Inputfirst you is given an integerT(t≤ten) indicating the number of test cases. For each test case, there is a numberN(0≤n≤) On a line representing the number of water sources.Nintegers follow, respectivelya1,a 2, a3 ,., An , and each integer are in{1,.. . ,6} . On the next line, there is a numberq(0≤q≤) Representing the number of queries. After that, there'll beQlines with integersl  and  r ( 1≤l ≤r ≤n ) /span> indicating the range of which you should find out the biggest water source.

Outputfor each query, output an integer representing the size of the biggest water source.

Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 22 33 3

Sample Output100 2 3 4 4 5 1 999999 999999 1

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 #defineINF 0x7fffffff7 intmaxv=-INF;8 structnode9 {Ten     intL,r; One     intMAXV; A     intMid () -     { -         return(L+R)/2; the     } -}tree[800020]; - voidBuildtree (intRootintLintR) - { +Tree[root].l=l; -Tree[root].r=R; +tree[root].maxv=-INF; A     if(l!=R) at     { -Buildtree (2*root+1, L, (l+r)/2); -Buildtree (2*root+2, (L+R)/2+1, R); -     } - } - voidInsertintRootintIintv) in { -     if(tree[root].l==TREE[ROOT].R) to     { +tree[root].maxv=v; -         return; the     } *tree[root].maxv=Max (tree[root].maxv,v); $     if(i<=Tree[root].mid ())Panax NotoginsengInsert (root*2+1, i,v); -     Else theInsert (root*2+2, i,v); + } A voidQueryintRootintSinte) the { +     if(maxv>=TREE[ROOT].MAXV) -         return; $     if(tree[root].l==s&&tree[root].r==e) $     { -maxv=Max (TREE[ROOT].MAXV,MAXV); -         return; the     } -     if(e<=Tree[root].mid ())WuyiQuery2*root+1, s,e); the     Else if(s>Tree[root].mid ()) -Query2*root+2, s,e); Wu     Else -     { AboutQuery2*root+1, S,tree[root].mid ()); $Query2*root+2, Tree[root].mid () +1, e); -     } - } - intMain () A { +     intt,n,m,i,j; theCin>>T; -      while(t--) $     { theCin>>N; theBuildtree (0,1, n); the          for(i=1; i<=n;i++) the         { -             inth; inCin>>h; theInsert0, i,h); the         } AboutCin>>m; the          for(i=0; i<m;i++) the         { the             ints,e; +Cin>>s>>e; -maxv=-INF; theQuery0, s,e);Bayiprintf"%d\n", MAXV); the         } the     } -     return 0; -}
View Code

ACM Changchun Division Registration Questions

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.