Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17190    Accepted Submission(s): 7266

Problem Description
At
the entrance to the university, there is a huge rectangular billboard
of size h*w (h is its height and w is its width). The board is the place
where all possible announcements are posted: nearest programming
competitions, changes 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.

 
Input
There are multiple cases (no more than 40 cases).

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
For
each announcement (in the order they are given in the input file)
output one number - the number of the row in which this announcement is
placed. Rows are numbered from 1 to h, starting with the top row. If an
announcement can't be put on the billboard, output "-1" for this
announcement.
 
Sample Input
3 5 5
2
4
3
3
3
 
Sample Output
1
2
1
3
-1
 
  这题不断维护最大值就可以了。
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int t[maxn<<];
int h,w,n,x; void Build(int node,int l,int r)
{
t[node]=w;
if(l==r)return;
int mid=(l+r)>>;
Build(node<<,l,mid);
Build(node<<|,mid+,r);
} void Query(int node,int l,int r,int q)
{
if(l==r){
printf("%d\n",l);
t[node]-=q;
return;
}
int mid=(l+r)>>,a=node<<,b=a+;
if(t[a]>=q)Query(a,l,mid,q);
else Query(b,mid+,r,q);
t[node]=max(t[a],t[b]);
return;
}
int main()
{
while(~scanf("%d%d%d",&h,&w,&n)){
h=min(n,h);
Build(,,h);
for(int i=;i<=n;i++){
scanf("%d",&x);
if(x>t[])
printf("-1\n");
else
Query(,,h,x);
}
}
return ;
}

线段树(维护最大值):HDU Billboard的更多相关文章

  1. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  2. hdu 5316 Magician 线段树维护最大值

    题目链接:Magician 题意: 给你一个长度为n的序列v,你需要对这个序列进行m次操作,操作一共有两种,输入格式为 type a b 1.如果type==0,你就需要输出[a,b]区间内的美丽序列 ...

  3. Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)

    E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. HDU 6406 Taotao Picks Apples 线段树维护

    题意:给个T,T组数据: 每组给个n,m:n个数,m个操作: (对序列的操作是,一开始假设你手上东西是-INF,到i=1时拿起1,之后遍历,遇到比手头上的数量大的数时替换(拿到手的算拿走),问最后拿走 ...

  5. hdu 5068 线段树维护矩阵乘积

    http://acm.hdu.edu.cn/showproblem.php?pid=5068 题意给的略不清晰 m个询问:从i层去j层的方法数(求连段乘积)或者修改从x层y门和x+1层z门的状态反转( ...

  6. 51nod 1376【线段树维护区间最大值】

    引自:wonter巨巨的博客 定义 dp[i] := 以数字 i(不是下标 i)为结尾的最长上升长度 然后用线段树维护 dp[i]: 每个节点维护 2 个信息,一个是当前区间的最大上升长度,一个是最大 ...

  7. HDU 6155 Subsequence Count 线段树维护矩阵

    Subsequence Count Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Oth ...

  8. hdu 4037 Development Value(线段树维护数学公式)

    Development Value Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others ...

  9. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

随机推荐

  1. error: device not found - waiting for device -

    执行 cocos run -p android 时报的这个错误 连接上 android 手机, 手机开启开发者模式.  设置--其他高级设置--开发者选项--USB 调试

  2. spring下载dist.zip

    http://repo.springsource.org/libs-release-local/org/springframework/spring/ 选择对应版本下载即可

  3. Bash常用快捷键

    快捷键 作用 Ctrl+A 把光标移动到命令行开头,如果我们输入的命令过长,想要把光标移动到命令行开头时使用 Ctrl+E 把光标移动到命令行结尾 Ctrl+C 强制终止当前的命令 Ctrl+L 清屏 ...

  4. 如何用visual studio控件(repeater)绑定数据库(SQL server)信息并显示

    今天学习了下如何间接绑定数据库网上看了很多信息,都云里雾里,没有图片说明,初学者完全看不懂,我自己做了一个DEMO,相信可以帮到大家! 一.建立数据库,并构建表信息,我的表信息如下: 表中的数据在数据 ...

  5. Asp.net MVC利用Ajax.BeginForm实现bootstrap模态框弹出,并进行前段验证

    1.新建Controller public ActionResult Index() { return View(); } public ActionResult Person(int? id) { ...

  6. 最终版-perl工具解析数据库的报告文件0120

    ********************需要根据自己的实际环境修改哦**************************** ******************** 1. 收集awr报告样本   a ...

  7. ASP.NET网站实现中英文转换(本地化资源)

    主要内容: 1. 简单例子 2. 进一步认识Localization 3. 语言转换 4. 解决方案 一. 简单例子 下面通过一个简单的例子来说明利用Localization来实现本地化是那么的简单, ...

  8. 【转】jquery两稳定版本比较~~

    博客分类: Web前端 jquery  jquery历经了多个版本的更新,版本上的比较貌似没什么必要性,一般来说新的版本会比旧的版本各方面都略有提升,但由于新版中增加了各种新的功能,难免会引起bug的 ...

  9. SGU 106.Index of super-prime

    时间限制:0.25s 空间限制:4M 题目大意:                 在从下标1开始素数表里,下标为素数的素数,称为超级素数(Super-prime),给出一个n(n<=10000) ...

  10. python everything is object

    python面向对象非常彻底,即使过程式的代码风格,python在运作的时候也是面向对象的.everything is object. 差异 在面向对象的理念上,python和非常工程化的面向对象语言 ...