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. Oracle 修改密码(忘记登录密码,用户System)

    1.修改计算机环境变量,把oracle服务端路径放在最前面 2.输入cmd 3.输入命令:sysplus /nolog SQL>conn sys/syspwd as sysdba SQL> ...

  2. linux学习笔记汇总

    linux 文件系统是采用级层树状的目录结构,采用"/"根目录的方式 目录结构: / 根目录           |---root: 存放root用户相关的文件          ...

  3. 2、替换空格------------>剑指offer系列

    题目 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 代码 1.直接用空格将字符串切割成 ...

  4. 一张图告诉你,只会这些HTML还远远不够!!!!!

    不知道自己HTML水平如何,不知道HTML5如何进化?看这张图 如果一半以上的你都不会,必须看这本书,阿里一线工程师用代码和功能页面来告诉你每一个技术点. 都会一点,但不知道如何检验自己,看看本书提供 ...

  5. gcc&g++

    原文章 误区一:gcc只能编译c代码,g++只能编译c++代码两者都可以,但是请注意:1.后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序:后缀为.cpp的,两者都会认为是c++程序,注 ...

  6. DataPicker以及TimePicker显示时间和日期(屏幕上显示)

    public class MainActivity extends Activity { private DatePicker date_picker;private TimePicker time_ ...

  7. Azure Linux 云主机使用Root超级用户登录

    Azure的Linux虚拟机是可以灵活使用root超级用户的管理员权限的: 1:使用sudo passwd root指令设置超级用户root密码: 使用创建Linux时设置的用户名和密码登陆,使用su ...

  8. cacti图形字符乱码

    环境:最小化centos+cacti 问题:图形监控界面字符全部乱码,如下图 解决方法:从windows下面拷贝一个ttf文件到/usr/share/fonts下面,刷新页面,字符就正常显示了.

  9. 解决flexpaper读取本地文件问题,JAVA+TOMCAT

    flexpaper是不可以用绝对路径的调用本地或项目外的swf文件的,这个我们就有两种方法,一种是把swf和项目放在同一个目录下面,通过相对路径来获取 另一种是在运行项目的tomcat的server. ...

  10. 洛谷 P1334 瑞瑞的木板==P2664 【题目待添加】

    题目描述 瑞瑞想要亲自修复在他的一个小牧场周围的围栏.他测量栅栏并发现他需要N(1≤N≤20,000)根木板,每根的长度为整数Li(1≤Li≤50,000).于是,他神奇地买了一根足够长的木板,长度为 ...