HDU 2795 Bulletin Board (single point maximum)

Source: Internet
Author: User

Test instructions: There is a bulletin board, the size of h*w, to paste n announcements, the length of each notice is x, the height is fixed to 1, the announcement to be as far as possible on and on the left, each given a notice, request this announcement in meeting the requirements of the situation decentralized in the first layer.

Sample Input
3 5 5
2
4
3
3
3

Sample Output
1
2
1
3
-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 =200010; One  A intmax[maxn<<2] ;//4 times times the knot. - intH, W, N; -  the voidPushup (intRt//Update to parent node - { -MAX[RT] = max (MAX[RT *2], Max[rt *2+1] );//RT is the current node. - } +  - voidBuildintLintRintRt//Building a segment tree + { AMAX[RT] =W; at     if(L = =R) -     { -         return ; -     } -     intm = (L + r)/2 ; -Build (L, M, RT *2) ; inBuild (M +1, R, RT *2+1) ; -  to } +  - intQueryintXintLintRintRt//The interval to find the maximum of the seat directly to the update operation in the query did the { *     if(L = =R) $     {Panax NotoginsengMAX[RT]-=x; -        returnL//each leaf node represents the row of the bulletin board the     } +     intm = (L + r)/2 ; A     intRET =0 ; the     if(MAX[RT *2] >=x) +ret = query (x, L, M, RT *2) ; -     Else $ret = query (x, m+1, R, RT *2+1) ; $ pushup (RT); -     returnret; - } the  - intMain ()Wuyi { the     //freopen ("In.txt", "R", stdin); -      while(SCANF (" %d%d%d", &h, &w, &n)! = EOF)//h is high w for width n for quantity Wu     { -         if(H >N) Abouth =N; $Build1H1); -          while(n--) -         { -            intx; Ascanf"%d", &x); +            if(X > max[1])//if the width of an announcement is greater than that of the 1-h, the remaining width of the range is not fit. theprintf"-1\n") ; -            Else $printf"%d\n", Query (x,1H1)) ; the         } the     } the  the     return 0 ; -}
View Code

HDU 2795 Bulletin Board (single point 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.