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 ...
随机推荐
- css中element element和element>element选择器的区别
就是这样的选择器: 比如html中有这样一段布局: <div> <p>我是一个段落</p> </div> 这时你用div p{background:ye ...
- 计算机图形学--旋转变换(java)
import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.Window ...
- 可爱的 Python : Python中的函数式编程,第三部分
英文原文:Charming Python: Functional programming in Python, Part 3,翻译:开源中国 摘要: 作者David Mertz在其文章<可爱的 ...
- MFC的规则DLL中资源使用的问题
今天刚刚做了一个静态链接到MFC的规则dll,即“Use MFC in a static library“,该dll用来显示一个窗体.然后在一个mfc可执行程序A.exe中调用这个dll文件,可以正常 ...
- javascript数组去重算法-----3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ios 后台模式
1.在后台可以继续播放音频 To play sound in the background, make sure to add the following to the Info.plist file ...
- JavaScript创建对象的模式
/** * Created by W_YH on 2016/3/14. */ /* 对象的创建方式 */ //------->第一种创建方式------创建Object的实例 var perso ...
- html系列教程--p param progress rp rt ruby script select small source
<p> 标签:用户段落划分或折行的标签 <param> 标签:param 元素允许您为插入 XHTML 文档的对象规定 run-time 设置,也就是说,此标签可为包含它的 & ...
- Ubuntu 14.04安装Sogou输入法
在http://pinyin.sogou.com/linux/?r=pinyin页面可下载对应的的deb包.在http://pinyin.sogou.com/linux/help.php页面有搜狗输入 ...
- RabbitMQ安装后启动出错:- unable to connect to epmd on blockstorage: timeout (timed out)
具体出错信息如下: [root@blockstorage ~]# rabbitmqctl change_password guest RABBIT_PASS Changing password for ...