Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11861    Accepted Submission(s): 5223

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
 
Sample Output
1
2
1
3
-1
 
Author
hhanger@zju
 
Source
 
Recommend
lcy
 

题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子
思路:每次找到最大值的位子,然后减去L
线段树功能:query:区间求最大值的位子

 #include<cstdio>
#include<string.h>
#include<algorithm> #define clr(x,y) memset(x,y,sizeof(x))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int N=2e5+;
using namespace std; int h,w,n,MAX[N<<]; void PushUp(int rt)
{
MAX[rt]=max(MAX[rt<<],MAX[rt<<|]);
} void build(int l,int r,int rt)
{
int m; MAX[rt]=w;
if(l==r) {
return;
} m=(l+r)>>;
build(lson);
build(rson);
} int query(int x,int l,int r,int rt)
{
int m,ret;
if(l==r) {
MAX[rt]-=x;
return l;
}
m=(l+r)>>;
ret=(MAX[rt<<]>=x) ? query(x,lson) : query(x,rson);
PushUp(rt);
return ret;
} int main()
{
int x;
while(~scanf("%d%d%d",&h,&w,&n)) {
if(h>n) h=n;
build(,h,);
while(n--) {
scanf("%d",&x);
if(MAX[]<x) puts("-1");
else printf("%d\n",query(x,,h,)); } } return ;
}

[HDU] 2795 Billboard [线段树区间求最值]的更多相关文章

  1. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  2. hdu 1754 I Hate It(线段树区间求最值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. hdu4521-小明系列问题——小明序列(线段树区间求最值)

    题意:求最长上升序列的长度(LIS),但是要求相邻的两个数距离至少为d,数据范围较大,普通dp肯定TLE.线段树搞之就可以了,或者优化后的nlogn的dp. 代码为  线段树解法. #include ...

  4. ACM学习历程—HDU 2795 Billboard(线段树)

    Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...

  5. poj3264(线段树区间求最值)

    题目连接:http://poj.org/problem?id=3264 题意:给定Q(1<=Q<=200000)个数A1,A2,```,AQ,多次求任一区间Ai-Aj中最大数和最小数的差. ...

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

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

  7. HDU 2795 Billboard 线段树,区间最大值,单点更新

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

  8. HDU 2795.Billboard-完全版线段树(区间求最值的位置、区间染色、贴海报)

    HDU2795.Billboard 这个题的意思就是在一块h*w的板子上贴公告,公告的规格为1*wi ,张贴的时候尽量往上,同一高度尽量靠左,求第n个公告贴的位置所在的行数,如果没有合适的位置贴则输出 ...

  9. HDU 2795 Billboard (线段树+贪心)

    手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...

随机推荐

  1. ubuntu apt 命令参数(转)

    apt-get是一条linux命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载软件或操作系统. apt-get update 在修改/etc/apt/sou ...

  2. (转)Linux监控工具

    需要监控Linux服务器系统性能吗?尝试下面这些系统内置或附件的工具吧. 大多数Linux发行版本都装备了大量的监控工具,这些工具提供了能用作取得相关信息和系统活动的量度指标. 你能使用这些工具发现造 ...

  3. GET方式的中文编码与解码

  4. Powershell使用管道

    管道并不是什么新事物,以前的Cmd控制台也有重定向的命令,例如Dir | More可以将结果分屏显示.传统的Cmd管道是基于文本的,但是Powershell是基于对象. PS> ls | Sor ...

  5. Linux企业级项目实践之网络爬虫(17)——存储页面

    在爬虫系统中数据的流量相当大,要处理的数据内容不仅包括爬虫系统的各种数据结构空间,而且包括从外部节点中得到的各种数据,比如HTTP请求,HTML页面,ROBOT.TXT等等.如果对这些内容处理不当,那 ...

  6. Manacher算法----最长回文子串

    题目描述 给定一个字符串,求它的最长回文子串的长度. 分析与解法 最容易想到的办法是枚举所有的子串,分别判断其是否为回文.这个思路初看起来是正确的,但却做了很多无用功,如果一个长的子串包含另一个短一些 ...

  7. sql的交叉连接,内连接,左外连接,右外连接,全外连接总结

    实践是最好的检验,一直都对这几个连接查询出来的结果有什么不同不大理解,然后自己放一块查询比较了一下,用结果来说话~ 先建两张表如下: t1: id name age 1 张三 18 2 李四 25 t ...

  8. Centos中安装Sublime编辑器

    Centos中安装Sublime编辑器 1.从官网下载相应操作系统的下的安装包(http://www.sublimetext.com/2),这里下的是linux下的安装包 2.解压安装包,并将其放在/ ...

  9. [HEOI 2013 day2] SAO (树形动态规划)

    题目大意 给一棵N个节点的有向树(N <= 1000),求其拓扑序列个数. 思路 我们将任意一个点作为根,用dp[i][j]表示以节点i为根的子树满足节点i在第j个位置上的拓扑序列的个数.在求节 ...

  10. [转载]date命令时间转换

    Linux时间戳和标准时间的互转 在LINUX系统中,有许多场合都使用时间戳的方式表示时间,即从1970年1月1日起至当前的天数或秒数.如/etc/shadow里的密码更改日期和失效日期,还有代理服务 ...