Billboard(线段树)
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16755 Accepted Submission(s): 7089
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.
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.
2
4
3
3
3
2
1
3
-1
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define P_ printf("")
#define PL(x) printf("%lld",x)
typedef long long LL;
const int INF=0x3f3f3f3f;
#define ll root<<1
#define rr root<<1|1
#define lson ll,l,mid
#define rson rr,mid+1,r
const int MAXN=200100;
int tree[MAXN<<2];
#define V(x) tree[x]
int w;
int ans;
void pushup(int root){
V(root)=max(V(ll),V(rr));
}
void build(int root,int l,int r){
V(root)=w;
if(l==r)return;
int mid=(l+r)>>1;
build(lson);
build(rson);
}
void query(int root,int l,int r,int v){
if(l==r){
V(root)-=v;
ans=l;return;
}
int mid=(l+r)>>1;
if(V(ll)>=v)query(lson,v);
else query(rson,v);
pushup(root);
}
int main(){
int h,n;
while(~scanf("%d%d%d",&h,&w,&n)){
if(h>n)h=n;
build(1,1,h);
while(n--){
int x;
SI(x);
ans=INF;
if(x>V(1)){
puts("-1");continue;
}
query(1,1,h,x);
printf("%d\n",ans);
}
}
return 0;
}
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 ...
- 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 ...
随机推荐
- CloudEra Email Search
http://blog.cloudera.com/blog/2013/09/email-indexing-using-cloudera-search/ http://blog.cloudera.com ...
- VBS解析时候遇到时间
http://msdn.microsoft.com/en-us/library/aa393687(v=vs.85).aspx MSDN说的很详细么. http://msdn.microsoft.com ...
- QStringList不是简单重命名的便利类,而是提供了额外的函数,比如sort和join等等
以前一直以为就是重命名而已,原来还不是.QT真伟大,方便到家了.该有的,全都有现成的.
- UVA1292-----Strategic game-----树形DP解决树上的最小点覆盖问题
本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...
- 【JavaScript脚本编程技术详解-----(一)】
首先说明,本系列教程是写给有一定的JavaScript编程基础的同学看的,最好还有其它的编程语言经验,因为里面可能涉及一些其它的程序设计语言写的源代码,这都是我自己总结的经验,我喜欢在学习一门新的编程 ...
- 解决itunesconnect无法訪问
今天打开https://itunesconnect.apple.com出现了无法訪问提示,例如以下图, 我起初以为苹果在维护呢,但想想,假设是维护提示页面也应该会友好些.带着疑问,google一搜,看 ...
- 【Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性
在进行UI布局的时候,可能常常会用到 android:gravity 和 android:layout_Gravity 这两个属性. 关于这两个属性的差别,网上已经有许多人进行了说明,这边再简单说一 ...
- VS中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
最近使用VS,在引用COM组件的时候,出现了无法嵌入互操作类型“……”,请改用适用的接口的错误提示.查阅资料,找到解决方案,记录如下: 选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型” ...
- Egret及Node.js的安装部署
最近在学Html5游戏开发,我选择的是国内的一个游戏开发框架egret.因为涉及到node.js这个近年来新兴起来的技术.借此机会把这方面知识学习一下. node.js以及egret的操作类似于Lin ...
- Struts 2.x Unable to load configuration. - action
问题分析:遇到该问题一般是struts中某个配置文件没有正确配置,比如: 1.class中的TestAction没有成功加载: <constant name="struts.i18n. ...