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. JS中对数组元素进行增删改移

    在js中对数组元素进行增删改移,简单总结了一下方法: 方法 说明 实例 push( ); 在原来数组中的元素最后面添加元素 arr.push("再见58"); unshift( ) ...

  2. 从零开始利用vue-cli搭建简单音乐网站(五)

    上一篇文章讲到的是如何利用mongoose从数据库读取数据然后更新页面,接下来要实现的就是用户注册登录功能,这个功能涉及到的东西太多了,今天只实现了登录功能,登陆之后更新导航条界面,最后效果如下: 登 ...

  3. Json字符串转excel表格文件

    假如我们有一段json串,该json串是由一系列结构相同的数据集合组成,如下: { "data": [ { "groupId": "com.test. ...

  4. Objective-C Operators and Expressions

    What is an Expression? The most basic expression consists of an operator, two operands and an assign ...

  5. Bootstrap 入门到精通

    介绍 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷.Bootstr ...

  6. UVA1001 Say Cheese (dijkstra)

    如果没有洞,那么任意两点的最短距离就是直线距离,洞里是瞬间的,所以看成一个点就行了(其实点也可以当作半径为0的洞来处理),洞到洞的最短距离都是圆心距离减去半径.剩下的就是求单源最短路径,是完全图,用不 ...

  7. BC div2补题以及 复习模除 逆元__BestCoder Round #78 (div.2)

    第一题没话说 智商欠费 加老柴辅导终于过了 需要在意的是数据范围为2的63次方-1 三个数相加肯定爆了 四边形的定义 任意边小于其余三边之和 换句话说就是 最长边小于其余三边之和 这样的话问题转化为 ...

  8. sping IOC的设计原理和高级特性

    1. IOC 是Spring的内核,字面意思是控制反转,并提出了DI依赖注入的概念. 2.Spirng 容器的设计中,一个是实现BeanFactory 接口的简单饿汉容器,另外一个是比较高级的Appl ...

  9. 汇编segment

    一个正常的应用程序被由若干个 segment组成. 定义 segment: SECTION .段名 SECTION 也可以小写 如: 定义数据段: section .data   定义代码段: sec ...

  10. 工程化---cnpm不是内部命令的解决

    (1)问题描述 安装完,执行cnpm -v发现报出不是内部命令. 安装成功如下图: (2)解决方案: 之前配置过默认安装都会在D:\\nodejs\node_global中,所有我们cd 到 这个路径 ...