hdu 2795 Billboard 线段树单点更新
Billboard
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=2795
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
Sample Output
2
1
3
-1
HINT
题意
有一个w*h的版,然后让你贴海报,海报贴的方法是,优先贴最高的,然后再贴最左边的
题解:
线段树单点更新
主要问题就是建树的时候,需要稍微注意一下,因为只有200000个海报,所以只要建200000这么大的树就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500010
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} struct node
{
int l,r,mx;
};
node a[maxn*];
int h,w,n;
void build(int x,int l,int r)
{
a[x].l=l,a[x].r=r;
a[x].mx=w;
if(l==r)
return;
int mid=(l+r)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
}
int update(int x,int val)
{
int l=a[x].l,r=a[x].r;
if(l==r)
{
a[x].mx-=val;
return l;
}
else
{
int ans=;
if(a[x<<].mx>=val)
ans=update(x<<,val);
else
ans=update(x<<|,val);
a[x].mx=max(a[x<<].mx,a[x<<|].mx);
return ans;
}
}
int d;
int main()
{
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
memset(a,,sizeof(a));
build(,,min(h,maxn));
for(int i=;i<n;i++)
{
d=read();
if(a[].mx<d)
puts("-1");
else
printf("%d\n",update(,d));
}
}
}
hdu 2795 Billboard 线段树单点更新的更多相关文章
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- HDU 2795 Billboard 线段树,区间最大值,单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795 Billboard (线段树+贪心)
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- ACM学习历程—HDU 2795 Billboard(线段树)
Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...
- hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值
Conturbatio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...
- [HDU] 2795 Billboard [线段树区间求最值]
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2795 Billboard 线段树活用
题目大意:在h*w 高乘宽这样大小的 board上要贴广告,每个广告的高均为1,wi值就是数据另给,每组数组给了一个board和多个广告,要你求出,每个广告应该贴在board的哪一行,如果实在贴不上, ...
随机推荐
- sql server 2008 r2 产品密钥
数据中心版:PTTFM-X467G-P7RH2-3Q6CG-4DMYBDDT3B-8W62X-P9JD6-8MX7M-HWK38==================================== ...
- 343.Integer Break---dp
题目链接:https://leetcode.com/problems/integer-break/description/ 题目大意:给定一个自然数,将其分解,对其分解的数作乘积,找出最大的乘积结果. ...
- java获取weblogic应用运行路径
String url = TemplateBuilder(当前类).class.getClassLoader().getResource("").getPath(); String ...
- ansible报错Aborting, target uses selinux but python bindings (libselinux-python) aren't installed
报错内容: TASK [activemq : jvm configuration] ********************************************************** ...
- [ python ] 初始面向对象
首先,通过之前学习的函数编写一个 人狗大战 的例子. 分析下这个需求,人 狗 大战 三个事情.角色:人.狗动作:狗咬人,人打狗 先创建人和狗两个角色: def person(name, hp, ag ...
- EnumSet基本用法
enum Season { SPRING, SUMMER, FALL, WINTER } public class EnumSetTest { public static void main(Stri ...
- Reverse Linked List I&&II——数据结构课上的一道题(经典必做题)
Reverse Linked List I Question Solution Reverse a singly linked list. Reverse Linked List I 设置三个指针即可 ...
- 关于Windows中的硬链接
https://zhidao.baidu.com/question/748233720330351012.html linux中使用硬链接 ln a.txt b.txt 查看硬链接 ls -il 关于 ...
- elk搭建实战
1 安装elasticsearch 1.1安装elasticsearch 相关中文文档:https://es.xiaoleilu.com 下载:从https://www.elastic.co/down ...
- NIO-3网络通信
import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import ja ...