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 ...
随机推荐
- 软件-集成开发环境:IDE
ylbtech-软件-集成开发环境:IDE 集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器. ...
- 南海区行政审批管理系统接口规范v0.3(规划) 3.业务办理API 3.1.businessAuditById【业务办理】
{"c_accept":"Q2015112400002","c_operators":"gz99","v_op ...
- [源码管理] Microsoft Visual SourceSafe 2005 下载与配置
一.VSS2005的下载地址是:百度搜索关键字:vss, 二.配置Microsoft Visual SourceSafe 2005的Internet访问 VSS2005发布以后,早就听说可以支持Int ...
- 同一sql程序执行比数据库执行慢
最近项目发现同一个sql在java端执行比在数据库执行慢很多,原因可能是程序的sql参数类型与数据库字段的类型不一致.
- ajax获取跨域数据
1.效果图 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %&g ...
- JavaScript的面向对象
JavaScript的对象 对象是JavaScript的一种数据类型.对象可以看成是属性的无序集合,每个属性都是一个键值对,属性名是字符串,因此可以把对象看成是从字符串到值的映射.这种数据结构在其他语 ...
- 纯CSS3文字Loading动画特效
纯CSS3文字Loading动画特效是一款个性的loading文字加载动画. 在线演示本地下载
- Mybatis xml约束文件的使用
一:准备.DTD约束文件 核心配置文件约束文件:mybatis-config.dtd <?xml version="1.0" encoding="UTF- ...
- ContentProvider 的使用
1.简单示例:通过ContentProvider暴露数据库,然后读取数据. 2.先加上一个工具类,用来使用copy assets下面的db文件代码如下: public class MyDBOpenHe ...
- 图片加载AsyncTask并发问题
在列表控件中使用AsycnTask加载图片时,会带来并发问题. 如果每个子视图都触发一个AsyncTask,因为AsyncTask内部是一个线程池,并发触发时,不能确保每个子视图的AsyncTask都 ...