[HDU] 2795 Billboard [segment tree interval to find the most value]

Source: Internet
Author: User

Billboard

Time limit:20000/8000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11861 Accepted Submission (s): 5223


Problem Descriptionat The entrance to the university, there are a huge rectangular billboard of size h*w (h is it height a nd w is its width). The board is the place where all possible announcements be posted:nearest programming competitions, changes in the Dinin G-menu, and other important information.

On September 1, the billboard is empty. One by one, the announcements started being put on the billboard.

Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.

When someone puts a new announcement on the billboard, she would all choose the topmost possible position for the Annou Ncement. Among all possible topmost positions she would always choose the leftmost one.

If There is no valid location for a new announcement, it's not put in the billboard (that's why some programming contests Has no participants from this university).

Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcement S is placed.

Inputthere is multiple cases (no more than-cases).

The first line of the input file contains three integer numbers, H, W, and N (1 <= h,w <= 10^9; 1 <= n <= 200, )-The dimensions of the billboard and the number of announcements.

Each of the next n lines contains an integer number WI (1 <= wi <= 10^9)-The width of i-th announcement.

Outputfor each announcement (in the order they is given in the input file) output one number-the number of the row in W Hich This announcement is placed. Rows is numbered from 1 to H and starting with the top row. If an announcement can ' t is put on the billboard, output "1" for this announcement.

Sample INPUT3 5 52433 3

Sample Output12 13-1

Author[email protected]

Sourcehdoj Summer Exercise (5)

Recommendlcy

Test instructions : h*w Board , put in some 1*l items , for each space can accommodate and the top of the seat
Idea : Find the maximum seat each time and subtract the L
Line segment Tree function : query: The seat of the interval to find the maximum value

1#include <cstdio>2#include <string.h>3#include <algorithm>4 5 #defineCLR (x, y) memset (x,y,sizeof (×))6 #defineLson l,m,rt<<17 #defineRson m+1,r,rt<<1|18 9 Const intn=2e5+3511;Ten using namespacestd; One  A inth,w,n,max[n<<2]; -  - voidPushup (intRT) the { -Max[rt]=max (max[rt<<1],max[rt<<1|1]); - } -  + voidBuildintLintRintRT) - { +     intm; A      atmax[rt]=W; -     if(l==r) { -         return; -     } -      -M= (l+r) >>1; in build (Lson); - build (Rson); to } +  - intQueryintXintLintRintRT) the { *     intM,ret; $     if(l==r) {Panax Notoginsengmax[rt]-=x; -         returnl; the     } +M= (l+r) >>1; ARet= (max[rt<<1]>=x)?query (X,lson): Query (X,rson); the pushup (RT); +     returnret; - } $  $ intMain () - { -     intx; the      while(~SCANF ("%d%d%d",&h,&w,&N)) { -         if(h>n) h=N;WuyiBuild1H1); the          while(n--) { -scanf"%d",&x); Wu             if(max[1]<x) puts ("-1"); -             Elseprintf"%d\n", Query (x,1H1)); About              $         } -          -     } -      A     return 0; +}

[HDU] 2795 Billboard [segment tree interval to find the most value]

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.