Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 9632    Accepted Submission(s): 4286
Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes
in the dining room menu, and other important information.



On September 1, the billboard was 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 always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.



If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have 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 announcements are placed.
 
Input
There are multiple cases (no more than 40 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.
 
Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't
be put on the billboard, output "-1" for this announcement.
 
Sample Input
3 5 5
2
4
3
3
3
 
Sample Output
1
2
1
3
-1

单点更新,区间最值。

#include <stdio.h>
#define maxn 200002
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1 int tree[maxn << 2];
int h, w, n, temp; int max(int a, int b)
{
return a > b ? a : b;
} void build(int l, int r, int rt)
{
if(l == r){
tree[rt] = w; return;
} int mid = (l + r) >> 1;
build(lson);
build(rson);
tree[rt] = w;
} void query(int val, int l, int r, int rt)
{
if(tree[rt] < val){
printf("-1\n"); return;
} if(l == r){
tree[rt] -= val;
printf("%d\n", r);
return;
} int mid = (l + r) >> 1;
if(tree[rt << 1] >= val) query(val, lson);
else query(val, rson); tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
} int main()
{
int t;
while(scanf("%d%d%d", &h, &w, &n) == 3){
build(1, t = h < n ? h : n, 1);
while(n--){
scanf("%d", &temp);
query(temp, 1, t, 1);
}
}
return 0;
}

HDU2795 Billboard 【线段树】+【单点更新】的更多相关文章

  1. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  2. HDU-------(2795)Billboard(线段树区间更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  4. hdu2795 Billboard(线段树单点修改)

    传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...

  5. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  6. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  7. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  8. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  9. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  10. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

随机推荐

  1. ORA-00923: 未找到要求的 FROM 关键字

    oracle处理 后台数据时, select a.oga01 发货单号,e.imaud04 箱/套from oga_file a left join ogb_file b on b.ogb01 = a ...

  2. python学习(一)

    1 python一切皆为对象,因为现实 包含了一系列的数据和操作这些数据的方法的一个整体,就叫作对象. 自行车 属性:手刹车,轮胎,脚踏板方法:如何前进的方法,控制停止的方法,控制方向 实际内容 男人 ...

  3. 初识Channel

    java.nio.channels 中的接口和类. A channel represents an open connection to an entity such as a hardware de ...

  4. (Problem 5)Smallest multiple

    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...

  5. 基于visual Studio2013解决算法导论之029二叉搜索树

     题目 二叉搜索树 解决代码及点评 #include <stdio.h> #include <malloc.h> #include <stdlib.h> ty ...

  6. Android 系统稳定性 - ANR(一)

    文章都为原创,转载请注明出处,未经允许而盗用者追究法律责任.很久之前写的了,留着有点浪费,共享之.编写者:李文栋  如果你是一个Android应用程序开发人员,你的人生中不可避免的三件事情是:死亡.缴 ...

  7. Android新增API之AudioEffect中文API与应用实例

    在Android2.3中增加了对音频混响的支持,这些API包含在android.media.audiofx包中. 一.概述 AudioEffect是android audio framework(an ...

  8. [译]URL和URI的区别

    译者:华科小涛:http://www.cnblogs.com/hust-ghtao/: 初学http协议,就被这两个相似的术语搞蒙了,查了很多资料,总算搞清楚了.(找资料还是英文啊,靠谱...). 本 ...

  9. Repeater控件

    一:http://www.cnblogs.com/foolin/archive/2011/08/31/2161342.html 二:http://www.cnblogs.com/shipfi/arch ...

  10. BZOJ 2875: [Noi2012]随机数生成器( 矩阵快速幂 )

    矩阵快速幂...+快速乘就OK了 ----------------------------------------------------------------------------------- ...