Hangzhou Electric HDU ACM 2795 Billboard (segment Tree camouflage version)

Source: Internet
Author: User
Tags integer numbers

Billboard Time limit:20000/8000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 14144 Accepted Submission (s): 6058


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 Input
3 5 524333

Sample Output
1213-1

Author[email protected]
Sourcehdoj Summer Exercise (5)

It's 11:30 ~ Oops! ~ and SB Crazy to brush the question ~.   Just brushed a line tree ~ so boring ... Tomorrow there is Hangzhou Electric multi-school joint refueling!
This topic is really hard to see whether it is the number of line segments, or do the line of tree-less problems ah. The height of the publicity fancy can be regarded as the length of the root node of the line segment, the width can be regarded as the value of each node, then the structure element needs a maximum value that holds the pluggable position in each of the nodes, because the update () function satisfies the preference to the lower left corner of the query insertion position. Once the insertion position is found, the information is updated recursively and the result is returned. Pay attention to the height of ad fancy
is a pretence. Then there's the code:
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include < string.h> #include <cctype> #include <string> #include <cmath> #include <vector> #include    <stack> #include <queue> #include <map> #include <set>using namespace Std;int h,x,n;struct tree{ int Left,right,max;}    Tree[200000<<2];int Create (int root, int left,int right) {tree[root].left=left;    Tree[root].right=right; if (left==right) {return tree[root].    Max=n;    } int a,b,mid= (left+right) >>1;    A=create (Root<<1,left,mid);    B=create (Root<<1|1,mid+1,right); Return Tree[root]. Max=max (A, b);}    int update (int root,int w) {int res; if (tree[root].left==tree[root].right) {Tree[root].        Max-=w;    return tree[root].left; } if (Tree[root<<1].    MAX&GT;=W) res= Update (ROOT&LT;&LT;1,W);    else res= update (ROOT&LT;&LT;1|1,W); Tree[root]. Max=max (Tree[root<<1]. Max,tREE[ROOT&LT;&LT;1|1].    MAX); return res;}        int main () {while (cin>>h>>n>>x) {if (h>x) h=x;        Create (1,1,H);            for (int i=1; i<=x; i++) {int w;            scanf ("%d", &w); if (tree[1].            MAX&LT;W) printf (" -1\n");        else printf ("%d\n", Update (1,W)); }    }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hangzhou Electric HDU ACM 2795 Billboard (segment Tree camouflage version)

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.