http://acm.hdu.edu.cn/showproblem.php?pid=2795
Billboard
problem Descriptionat the entrance to the university, there are a huge rectangular billboard of size h*w (h is it height and W is it wid TH). 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 in the billboard, she would always choose the topmost possible position for the A Nnouncement. 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 cont ESTs 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 announce ments 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,000)-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 WHI CH 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 Output1213-1
#include <cstdio>#include<cstring>using namespacestd;#defineN 200005#defineLson rt<<1,l,m#defineRson Rt<<1|1,m+1,rstructnode{intvalue;} Tree[n<<2];/*Line tree Remember to use the small values of H and N to build the idea is difficult to think: the value of each interval can be set to the maximum length of the interval and then with the input Len to compare test instructions require priority left, so if the left son placed priority left son, Look at the right son, then. pushup Update parent node information if the root node is the first node, the whole tree must not have a range to put the ad*/voidBuild (intRtintLintRintk) {Tree[rt].value=K; if(L==R)return ; intM= (l+r) >>1; Build (LSON,K); Build (rson,k);}intQuery (intRtintLintRintLen) { intans; if(l==R) {Tree[rt].value-=Len; returnl; } intM= (l+r) >>1;//if left can be put down, priority left, or see right can put down if(tree[rt<<1].value>=len) ans=Query (Lson,len); Elseans=Query (Rson,len);//Tree[rt].value=max (tree[rt<<1].value,tree[rt<<1|1].value);//pushup if(tree[rt<<1].value>=tree[rt<<1|1].value) Tree[rt].value=tree[rt<<1].value; Elsetree[rt].value=tree[rt<<1|1].value; returnans;}intMain () {intH,w,n; while(~SCANF ("%d%d%d",&h,&w,&N)) { if(h>n) h=N; Build (1,1, h,w); while(n--){ intLen; scanf ("%d",&Len); if(tree[1].value<len) printf ("-1\n"); Elseprintf"%d\n", Query (1,1, H,len)); } } return 0;}
HDU 2795:billboard (segment tree)