hdu2795(Billboard)线段树
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8266 Accepted Submission(s): 3676
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 <stdio.h>
#include <string.h>
#include <algorithm>
#define N 200005
using namespace std;
int segtree[N << ];
int update(int l, int r, int p, int v)//更新并返回结果
{
if (l < r)
{
if (segtree[p] >= v)//说明有结果
{
int mid = (l + r) >> , pp = p << , ans;
if (segtree[pp] >= v)//结果在左区间
ans = update(l, mid, pp, v);
else//结果在右区间
ans = update(mid + , r, pp + , v);
segtree[p] = max(segtree[pp], segtree[pp + ]);
return ans;
}
else
return -;
}
else
{
segtree[p] -= v;
return l;
}
} int main()
{
int h, w, n, i, t, tt;
while (~scanf("%d%d%d", &h, &w, &n))
{
for (i = ; i < (N << ); i++)
segtree[i] = w;
tt = min(h, n);
for (i =; i <= n; i++)
{
scanf("%d", &t);
if (t > w)//不需查询
{
printf("-1\n");
continue;
}
printf("%d\n", update(, tt, , t));
}
}
}
hdu2795(Billboard)线段树的更多相关文章
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu2795 Billboard(线段树单点修改)
传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...
- 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 ...
- 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 ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
随机推荐
- [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925
题目传送门 继续dp刷题计划,看到这道题,第一眼感觉不就是显然的完全背包嘛.把背包打完要开始填充数组大小的时候成为了mengbier,发现数据极大,达到了1e18.显然这不是一道平凡的背包题目. 于是 ...
- 删除一个ppa
https://itsfoss.com/how-to-remove-or-delete-ppas-quick-tip/ 总结如下: 1: 桌面删除,进入software & update,然后 ...
- parse.urljoin
parse.urljoin(former,later): 用former的域名拼接later的路径,如果later有域名,则进行忽略
- jvm 实战
https://blog.csdn.net/neutrojan/article/details/50532590# 1.ps -ef |grep java 找出最耗性能的JAVA进程2.top -Hp ...
- KMP算法笔记(云笔记图片版)
- 1-6static关键字
static的作用? static可以修饰变量,被static修饰的变量叫做静态变量,程序运行时静态变量存放在方法区里面,因此,静态变量在类加载阶段赋值,并且只赋值一次.请看例1 static可以修饰 ...
- web 前端的一些问题
1. HTML 和 JS 一个网页显示出来的静态的内容为html创见的静态object 对这些object的操作通过JS来响应 2. HTTP cookie cookie是由server set, 由 ...
- qconbeijing2014
http://2014.qconbeijing.com/videoslides.html 周一 周二 周三 周四 周五 周六 2014年5月19日 Deep Dive into Amazon's ...
- P2614 计算器弹琴
题目描述 总所周知,计算器可以拿来干很多它本不应该干的事情,比如写作文.(参看洛谷P2549) 小A发现了一个计算器的另一个隐藏功能——弹琴. http://www.bilibili.com/vide ...
- PHP的加密方式
1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str -- 原始字符串. raw_output -- ...