hdoj 2795 Billboard 【线段树 单点更新 + 维护区间最大值】
Billboard
in the dining room menu, and other important information.
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.
be put on the billboard, output "-1" for this announcement.
3 5 5
2
4
3
3
3
1
2
1
3
-1
#include <cstdio>
#include <algorithm>
#include <iostream>
#define ll o<<1
#define rr o<<1|1
using namespace std;
const int MAXN = 2 * 1e5 + 10;
struct Tree { int l, r, Max; }tree[MAXN<<2];
void PushUp(int o) {
tree[o].Max = max(tree[ll].Max, tree[rr].Max);
}
void Build(int o, int l, int r, int v) {
tree[o].l = l; tree[o].r = r; tree[o].Max = v;
if(l == r) { return ; }
int mid = (l + r) >> 1;
Build(ll, l, mid, v); Build(rr, mid+1, r, v);
}
void Update(int o, int pos, int v) {
if(tree[o].l == tree[o].r) {
tree[o].Max += v;
return ;
}
int mid = (tree[o].l + tree[o].r) >> 1;
if(pos <= mid) Update(ll, pos, v);
else Update(rr, pos, v);
PushUp(o);
}
int Query(int o, int v) {
if(tree[o].l == tree[o].r) {
return tree[o].l;
}
if(tree[ll].Max >= v) return Query(ll, v);
else return Query(rr, v);
}
int main()
{
int h, w, n;
while(scanf("%d%d%d", &h, &w, &n) != EOF) {
Build(1, 1, min(n, h), w);
for(int i = 1; i <= n; i++) {
int v; scanf("%d", &v);
if(tree[1].Max >= v) {
int id = Query(1, v);
printf("%d\n", id);
Update(1, id, -v);
}
else {
printf("-1\n");
}
}
}
return 0;
}
hdoj 2795 Billboard 【线段树 单点更新 + 维护区间最大值】的更多相关文章
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- HDU 1754 I Hate It 【线段树单点修改 维护区间最大值】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others ...
- hdu 1754 线段树 单点更新 动态区间最大值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- poj 2892---Tunnel Warfare(线段树单点更新、区间合并)
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...
- HDU - 1754 线段树-单点修改+询问区间最大值
这个也是线段树的经验问题,待修改的,动态询问区间的最大值,只需要每次更新的时候,去把利用子节点的信息进行修改即可以. 注意更新的时候区间的选择,需要对区间进行二分. #include<iostr ...
- nyoj 568——RMQ with Shifts——————【线段树单点更新、区间求最值】
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 In the traditional RMQ (Range Minimum Q ...
- HDU1754 —— I Hate It 线段树 单点修改及区间最大值
题目链接:https://vjudge.net/problem/HDU-1754 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜 ...
- hdu1166(线段树单点更新&区间求和模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...
随机推荐
- php gd
imagecopy() 函数用于拷贝图像或图像的一部分. imagecopyresized() 函数用于拷贝部分图像并调整大小. imagecopy() imagecopy() 函数用于拷贝图像或图像 ...
- 将我们的parser转换成Monad
还记得我们上一篇delegate类型的parser吗 ,在开始本篇之前,强烈建议你复习一下这个parser定义 public delegate Maybe<Tuple<T,string& ...
- 利用javascript(自定义事件)记录尺寸可变元素的尺寸变化过程
1.效果图 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %&g ...
- tab选项卡切换(js原生、jQuery )
思路: ① 遍历Tab选项 ② 然后给每个Tab选项绑定点击事件 ③ 每次点击时清除所有Tab选项及Tab选项内容的样式,然后给当前Tab选项添加标记样式,给当前Tab选项添加显示样式 <!DO ...
- lz的第一个RN项目
这是lz 成功在原有项目上集成的第一个ReactNative 项目. 参考官方网址: http://reactnative.cn/docs/0.43/integration-with-existing ...
- hdu2680 Choose the best route 最短路(多源转单源)
此题中起点有1000个,边有20000条.用链式前向星建图,再枚举起点用SPFA的话,超时了.(按理说,两千万的复杂度应该没超吧.不过一般说计算机计算速度 1~10 千万次/秒.也许拿最烂的计算机来卡 ...
- ACM 手机短号问题
手机短号 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description ...
- (转)基于MVC4+EasyUI的Web开发框架形成之旅--总体介绍
http://www.cnblogs.com/wuhuacong/p/3281103.html 最近花了很多时间在重构和进一步提炼Winform开发框架的工作上,加上时不时有一些项目的开发工作,我博客 ...
- RabbitMQ学习之集群镜像模式配置
1.增加负载均衡器 关于负载均衡器,商业的比如F5的BIG-IP,Radware的AppDirector,是硬件架构的产品,可以实现很高的处理能力.但这些产品昂贵的价格会让人止步,所以我们还有软件负载 ...
- Associated Values & enum
it is sometimes useful to be able to store associated values of other types alongside these case val ...