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 ...
随机推荐
- 《零基础学习Python》01
前言 Python是一种跨平台的语言 安装Python(Mac OS X) 1.在www.python.org/downloads 中下载Python,然后像安装其他软件一样进行安装. 2.打开: 找 ...
- win7下设置 WiFi AP
开启windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP),就可以让计算机变成无线路由器.实现共享上网. 1.以管理员身份运行命令提示符: “开始”---在搜索栏输入“cmd”-- ...
- oracle 和informix 的基础区别
1:查看表空间 select b.file_name 物理文件名, b.tablespace_name 表空间, b.bytes/1024/1024 大小M, (b.bytes-sum(nvl(a.b ...
- db2 for linux
https://www6.software.ibm.com/sdfdl/v2/regs2/db2pmopn/db2_v101/expc/Xa.2/Xb.aA_60_-idYiSFeSuWlF5-w4v ...
- Linux学习笔记3-VI 和 VIM的使用
vi: Visual Interface vim: VI iMproved 全屏编辑器, Linux系统下最强大的两款编辑器,vi和vim,vi是Linux本身自带的一款编辑器,纯文本编辑不带任何效果 ...
- c++中自增(++)和自减(--)操作符
自增(++)和自减(--)操作符为对象加1 或减1 操作提供了方便简短的实现方式.它们有前置和后置两种使用形式.到目前为止,我们已经使用过前自增操作,该操作使其操作数加1,操作结果是修改后的值.同理, ...
- Guestinfo.hbm(1)The markup declarations contained or pointed to by the document type declaration must be well-formed
今天启动ssh项目是居然报错了,还提示要联网启动,看了看错误信息发现,肯定是Hibernate映射文件的声明头出错了,仔细一下: hbm.xml中的dtd头直接是连接www.hibernate.org ...
- CentOS6.4下搭建hadoop2.2(64bit)注意事项
注:本文针对64位机器,32bit课直接tar -zxvf hadoop-2.2.0.tar.gz 解压配置即可. Step1:安装jdk(6以上版本) Step2:下载hadoop--->ht ...
- EXCEL破冰之旅
1 背景 EXCEL用于日常数据分析的工具中,最便利并且最强大的莫属透视表了.因为透视表对原始数据有一定的要求,所以本次的破冰之旅也将把焦点放在如何整理基础数据这个方面. 1.1 初识透视表 ...
- Java SE基础部分——常用类库之NumberFormat(数字格式化)
数字格式化常用方法:DecimalFormat和NuberFormat. //2016060524 数字格式化学习 //数字格式化 两种方法 一种直接使用NumberFormat,另一种Decimal ...