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 ...
随机推荐
- 我最优惠网系列(1)——HTML 解析类库HtmlAgilityPack
0. 序言 在开发我最优惠网的过程中,遇到一些问题和技术点,写出来和大家分享,也是我自己对近期工作的整理和记录,预计会有解析HTML类库.本地缓存.链接跳转和C#中执行js代码技巧等方面. 1. Ht ...
- 如何把apk编译时间和最后次git commit的sha值,写入到app中
需求背景:我们修复Bug的时候,频繁提交APK包,导致测试同学搞不清哪个包才是最新的 比如一个版本3.0.1,我们可能后续基于这个版本陆续提交了好几个修复包 同时,如果服务端ip地址能在界面上配置的话 ...
- this,this,再次讨论javascript中的this,超全面
至于js中this这个东西,好多淫解释过了,看起来好高端的样子,不造你看懂了木有? 先引用比较高端的,“汤姆大叔“ 的,yes this 好了,下面加上鄙人比较挫的解释 论点: this 不是变量,不 ...
- 【BZOJ1007】【HNOI2008】水平可见直线(斜率排序+单调栈)
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2605 Solved: 914[Submit][Stat ...
- WCF 入门 (21)
前言 再不写一篇就太监了,哈哈. 第21集 WCF里面的Binding Bindings in WCF 其实不太了解为什么第21集才讲这个Binding,下面都是一些概念性的东西,不过作为一个入门视频 ...
- Bootstrap3.0学习第十六轮(进度条、媒体对象、列表组、面板)
详情请查看http://aehyok.com/Blog/Detail/23.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 图解Android - Looper, Handler 和 MessageQueue
Looper, Handler 和 MessageQueue 是Android 的异步消息处理机制
- opencv笔记3:trackbar简单使用
time:2015年 10月 03日 星期六 13:54:17 CST # opencv笔记3:trackbar简单使用 当需要测试某变量的一系列取值取值会产生什么结果时,适合用trackbar.看起 ...
- codevs3243 区间翻转
题目描述 Description 给出N个数,要求做M次区间翻转(如1 2 3 4变成4 3 2 1),求出最后的序列 输入描述 Input Description 第一行一个数N,下一行N个数表示原 ...
- UVA 1626 Brackets sequence(括号匹配 + 区间DP)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/E 题意:添加最少的括号,让每个括号都能匹配并输出 分析:dp ...