Billboard(线段树)
Description
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
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
Sample Input
2
4
3
3
3
Sample Output
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(线段树)的更多相关文章
- HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [HDU] 2795 Billboard [线段树区间求最值]
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Billboard(线段树)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795 Billboard 线段树,区间最大值,单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- ACM学习历程—HDU 2795 Billboard(线段树)
Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...
- hdu2795(Billboard)线段树
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- HDU 2795 Billboard (线段树+贪心)
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...
随机推荐
- Gitlab的develop角色的人没有权限无法提交的问题解决方案
问题 事情是这样的,最近跟几位同事搞一些东西,打算在Gitlab上建一个仓库,然后协同开发. 我建好仓库,将其他几位同事添加进来,角色分配为Develop. 之后提交初始代码到master分支后,他们 ...
- web安全——简介
简介 不对外提供服务是最安全的. 安全是基于信任.如果信任失败了,则没有安全.比如你给一个ip加白名单,结果这个ip对你发动了安全攻击. 在非常明确需要提供服务的时候才对外提供服务,即白名单.其他的全 ...
- 怎样将SQL Azure数据库备份到本地或者Storage
怎样备份SQL Azure数据库到本地或者云存储Storage,可以使用SQL Database Import Export 的功能. 具体操作如下: 用SSMS链接SQL Azure数据库 注意:服 ...
- 第四十课:CSS3 transition详解
W3C中对transition是这样描述的:允许css的属性值在一定的时间内平滑的过渡,也就是说,以动画的效果改变css的属性值. transition主要包含4个属性值:transition-pro ...
- iBATIS sqlMapConfig配置详解
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC & ...
- iOS开发小技巧--初始化项目中修改APP安装后的名称
- ovs-agent流程
1. 代码流程分析 neutron/plugins/openvswitch/agent/ovs_neutron_agent.py:main() plugin = OVSNeutronAgent(**a ...
- js中的with语句
javascript中的with语句是什么? with 语句可以方便地用来引用某个特定对象中已有的属性,但是不能用来给对象添加属性.要给对象创建新的属性,必须明确地引用该对象. 看起来 ...
- BZOJ-4424 &&CodeForces-19E Fairy DP+dfs (Link-Cut-Tree可A)
Va爷的胡策题T2 E. Fairy time limit per test1.5 seconds memory limit per test256 megabytes inputstandard i ...
- git使用记录
唔,git有本地版本管理功能,所以,这个完全是可以拿来自己做版本管理的.所以有必要学习一下,另外,在oschina上开了个账户,用来管理自己一些代码,也是增加自己学习git的动力. 1. 使用clon ...