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. HoloToolkit项目源码剖析 - Spatial Mapping功能实现

    就像我之前所描述的,HoloToolkit项目是微软基于Unity内置的底层API封装的一套工具集合,帮助我们快速使用Unity集成开发HoloLens应用. 本文主要通过源码研究其中Spatial ...

  2. PM2实用入门指南

    简介 PM2是node进程管理工具,可以利用它来简化很多node应用管理的繁琐任务,如性能监控.自动重启.负载均衡等,而且使用非常简单. 下面就对PM2进行入门性的介绍,基本涵盖了PM2的常用的功能和 ...

  3. 基于int的Linux的经典系统调用实现

     先说明两个概念:中断和系统调用 一 系统调用: 是应用程序(运行库也是应用程序的一部分)与操作系统内核之间的接口,它决定了应用程序是如何和内核打交道的. 1,  Linux系统调用:2.6.19版内 ...

  4. css清楚浮动的几种常用方法

    请先看博客:http://www.jb51.net/css/173023.html

  5. 第三章:javascript: 列表

    在日常生活中,人们经常使用列表:待办事项列表,购物清单,十佳榜单,最后十名榜单等.计算机也在使用列表,尤其是列表中元素保存的是太多时.当不需要一个很长的序列中查找元素,或对其进行排序时,列表显得尤为有 ...

  6. Sublime Text 3 绝对神器

    距第一篇的开箱水文,已经有4个月的时间了,但因为懒,就没有下文了.终于,今天,我觉得写一篇准技术文章了. 忘记了是怎么开始用的ST,应该是在网上看到别人推荐才用到吧,用了有半年了.在windows下是 ...

  7. Java线程池应用

    Executors工具类用于创建Java线程池和定时器. newFixedThreadPool:创建一个可重用固定线程数的线程池,以共享的无界队列方式来运行这些线程.在任意点,在大多数 nThread ...

  8. oracle 分区表

    分区表用途 分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明.Oracle的分区表可以包括多个分区,每个分区都是一个独立的段(SEGMENT),可以存放到不同的表空间 ...

  9. xml文件的读写操作

    1.直接上代码:包含了xml文档的创建,读取xml文档,创建根节点,向根节点中添加子节点,保存xml文档----------先来张效果图: static void Main(string[] args ...

  10. SVN 服务器端安装过程

    1.安装软件版本: VisualSVN-Server-2.1.5.msi 右击安装软件,单机“安装” 2.单击[Next] 选择“I accept the terms in the License A ...