Billboard

Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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>
#include <algorithm>
#define lson o << 1 , l , mid
#define rson o << 1 | 1 , mid + 1 , r
using namespace std; int h , w , n ;
int maxn[] ;
int x ; void build ( int o , int l , int r )
{
maxn[o] = w ;
if ( l == r ) {
return ;
}
int mid = ( l + r ) >> ;
build ( lson ) ;
build ( rson ) ;
} int query ( int o , int l , int r )
{
if ( l == r ) {
maxn[o] -= x ;
return l ;
}
int mid = ( l + r ) >> , ret ;
if ( x <= maxn[o << ] ) {
ret = query ( lson ) ;
}
else {
ret = query ( rson ) ;
}
maxn[o] = max ( maxn[o << ] , maxn[o << | ] ) ;
return ret ;
}
int main ()
{
// freopen ( "a.txt" , "r" , stdin ) ;
while ( scanf ("%d%d%d" , &h , &w , &n ) != EOF ) {
if ( h > n )
h = n ;
build ( , , h ) ;
for (int i = ; i <= n ; i++ ) {
scanf ( "%d" , &x ) ;
if ( x > maxn[] ) {
printf ("-1\n") ;
}
else {
printf ("%d\n" , query ( , , h ) ) ;
}
}
}
return ;
}

因为 h <= 10^9 , 而 n <= 200,000 , 所以设node时 ,不要忘记 if ( h > n ) h = n ;这步

Billboard(线段树)的更多相关文章

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

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

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

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

  3. [HDU] 2795 Billboard [线段树区间求最值]

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

  4. Billboard(线段树)

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

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

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

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

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

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

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

  8. hdu2795(Billboard)线段树

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

  9. HDU 2795 Billboard (线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告;   然后给n个1*wi的广告,要求把广告贴 ...

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

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

随机推荐

  1. idea 重写toString()模板,转成json格式

    idea toString()模板,将对象toString()为json格式. 1. 2.点击新增 public java.lang.String toString() { final java.la ...

  2. STM32的bulk双缓冲传输速度的讨论,硬件的坑永远填不完

    详情:http://bbs.21ic.com/forum.php?mod=viewthread&tid=109584   USB 1.0的最高12Mbps. USB 2.0的高速模式480Mb ...

  3. 整合 Bing translator 到自己的系统中

    整合这个功能, 是因为 aliexpress 的买家来自不同国家, 我的 "小卖家" 同步到买家的留言, 很多西班牙,俄罗斯等小语种的文字, 看不懂. Google 被墙, 基本很 ...

  4. Extension 代表的是私有成员变量

    不明白就问百度.百度搜索得到的结果总是那么多却总是那么千篇一律.不晓得是什么原因. 刚完成一个项目.需要整理一下知识点. 在新项目开始的时候就比较矛盾.因为以前的项目中都有BaseViewContro ...

  5. 09.C#委托转换和匿名方法(五章5.1-5.4)

    今天将书中看的,自己想的写出来,供大家参考,不足之处请指正.进入正题. 在C#1中开发web form常常会遇到使用事件,为每个事件创建一个事件处理方法,在将方法赋予给事件中,会使用new Event ...

  6. python 读写文件和设置文件的字符编码

    一. python打开文件代码如下: f = open("d:\test.txt", "w") 说明:第一个参数是文件名称,包括路径:第二个参数是打开的模式mo ...

  7. beta版本工作百分比

    1.附上github上,beta阶段的整体工作情况 2.beta版本分工情况: 马凛凛 031302620(组长):主要负责任务分配和规划,编码工作主要是系统的“实时编辑”功能,以及服务器的配置和部署 ...

  8. 【转】Dubbo_与Zookeeper、SpringMVC整合和使用(负载均衡、容错)

    原文链接:http://blog.csdn.net/congcong68/article/details/41113239 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服 ...

  9. 【bzoj1853】 Scoi2010—幸运数字

    http://www.lydsy.com/JudgeOnline/problem.php?id=1853 (题目链接) 今天考试考了容斥,结果空知道结论却不会写→_→ 题意 求区间中不含6,8两个数字 ...

  10. HDU2509 Be the Winner

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...