D. Billboard

Time Limit: 8000ms
Case Time Limit: 8000ms
Memory Limit: 32768KB
 
64-bit integer IO format: %I64d      Java class name: Main
 
 
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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int maxn = ;
struct node {
int lt,rt,lmax,rmax;
} tree[maxn<<];
int h,w,n,ans;
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
if(lt == rt) {
tree[v].lmax = tree[v].rmax = w;
return;
}
int mid = (lt+rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
tree[v].lmax = max(tree[v<<].lmax,tree[v<<].rmax);
tree[v].rmax = max(tree[v<<|].lmax,tree[v<<|].rmax);
}
void add(int val,int v) {
if(val > max(tree[v].lmax,tree[v].rmax)) {
ans = -;
return;
}
if(tree[v].lt == tree[v].rt) {
if(tree[v].lmax >= val) {
ans = tree[v].lt;
tree[v].lmax -= val;
tree[v].rmax -= val;
} else ans = -;
return;
}
if(val <= tree[v].lmax) add(val,v<<);
else add(val,v<<|);
tree[v].lmax = max(tree[v<<].lmax,tree[v<<].rmax);
tree[v].rmax = max(tree[v<<|].lmax,tree[v<<|].rmax);
}
int main() {
int temp;
while(~scanf("%d %d %d",&h,&w,&n)) {
if(h > n) h = n;
build(,h,);
while(n--) {
scanf("%d",&temp);
ans = -;
add(temp,);
printf("%d\n",ans);
}
}
return ;
}

D. Billboard的更多相关文章

  1. HDU 2795 Billboard(区间求最大值的位置update的操作在query里做了)

    Billboard 通过这题,我知道了要活用线段树的思想,而不是拘泥于形式, 就比如这题 显然更新和查询放在一起很简单 但如果分开写 那么我觉得难度会大大增加 [题目链接]Billboard [题目类 ...

  2. 三维场景中使用BillBoard技术

    三维场景中对于渲染效果不是很精致的物体可以使用BillBoard技术实现,使用该技术需要将物体实时朝向摄像机,即计算billboard的旋转矩阵M. 首先根据摄像机位置cameraPos和billBo ...

  3. HDU 2795 Billboard(线段树)

    题目链接: 传送门 Billboard Time Limit: 2000MS     Memory Limit: 32768 K Description At the entrance to the ...

  4. ACM: Billboard 解题报告-线段树

     Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descript ...

  5. 【hdu2795】Billboard

    Problem Description At the entrance to the university, there is a huge rectangular billboard of size ...

  6. Billboard(线段树)

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. HDU 2795 Billboard(线段树的另类应用)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU-------(2795)Billboard(线段树区间更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. UVALive 3953 Strange Billboard (状态压缩+枚举)

    Strange Billboard 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/A Description The marke ...

  10. HDU 1882 Strange Billboard(位运算)

    题目链接 题意 : 给你一个矩阵,有黑有白,翻转一个块可以让上下左右都翻转过来,问最少翻转多少次能让矩阵变为全白. 思路 : 我们从第一行开始枚举要翻转的状态,最多可以枚举到2的16次方,因为你只要第 ...

随机推荐

  1. 【学习笔记】CSS优先级规则

    CSS的优先级规则很多地方的说法都是错误的,常见错误说法是inline css>内部样式>外部样式,其实并没有这种规定.真正的CSS优先级确定是通过特性值大小确定的,在特性值大小相同的情况 ...

  2. Nginx常用命令介绍

    #安装nginx准备工作yum install gcyum -y install pcre-develyum install -y zlib-devel #编译安装./configuremake &a ...

  3. Scroller 界面滑动

    Scroller 滑动之后滑动器子标签里面的控件,其自身是不动的.这里点在下面的进阶会体现出来.  1. 继承LinearLayout, 相对布局也可以. public class MyLinearL ...

  4. android 焦点 ListView 点击事件获取失败

    1. 在ListView 中, 创建一个app_item.xml 布局文件 在布局文件中有如下的代码:  <CheckBox         android:id="@+id/cb_t ...

  5. 在idea下创建maven

    之前一直用eclipse,现在要用idea写一个安装过程玩玩 一:New Project 二:选择maven,在project SDK上选择你安装的jdk,默认安装在c:/Program Files ...

  6. perl 引用(数组和hash引用) --- perlreftut - Mark 的一个简单的'引用'教程 ---Understand References Today. --Mark Jason Dominus, Plover Systems (mjd-perl-ref+@plover.com)

    https://blog.csdn.net/fangwei1235/article/details/8570886 首页 博客 学院 下载 论坛 APP 问答 商城 活动 VIP会员 招聘 ITeye ...

  7. 清理数据库事务——SQL语句

    清除流程内部的所有相关数据 eg1: declare @procedureTemp table ( [ProcedureCode] varchar(10) ) declare @ProcedureCo ...

  8. linux虚拟机安装值得注意的几点

    1.建立新的虚拟机时选择自定义安装并选择稍后安装操作系统 2.关键安装命令 tar -xzvf  VMwareTools-10.0.6-3595377.tar.gz sudo ./wmware-ins ...

  9. 有C++特色的极乐净土

    闲的没事瞎打的 在win7下会走调,需要将win7的beep系统文件改成xp的,且主机装有蜂鸣器才能正常收听. beep文件的度盘地址(不过应该没人为了听个这个去改系统文件)(P.S.如果想要尝试,尽 ...

  10. 830. Positions of Large Groups@python

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...