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 ;
}

最新文章

  1. CSS字体记录
  2. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版新增系统参数管理
  3. 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
  4. 原创:goldengate从11.2升级到12.1.2
  5. IE7 -- 鼠标移入显示下拉框 不显示的问题 / 以及宽度问题
  6. A4纸网页打印——宽高设置
  7. 虚拟化之xenserver
  8. linux中Apache更Nginx环境配置教程
  9. 译文:javascript function中的this
  10. (转载)有关反演和gcd
  11. Android开发视频学习(1)
  12. Android监测手指上下左右滑动屏幕
  13. java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext
  14. java框架之SpringBoot(10)-启动流程及自定义starter
  15. 让docker容器开机启动
  16. linux文件管理之查找
  17. 银行卡号码校验算法(Luhn算法,又叫模10算法)
  18. shell快捷方式总结
  19. ABAP-ALV详解
  20. c++11多线程学习笔记之二 mutex使用

热门文章

  1. Nacos部署中的一些常见问题汇总
  2. 2189 数字三角形W
  3. ACCESS中通过一个字段补齐更新另一个字段
  4. 基于phpExcel写的excel类(导出为Excel)
  5. 再用python写一个文本处理的东东
  6. Software Engineer(百赴美)
  7. codevs 2776 寻找代表元
  8. POJ 1998 Cube Stacking
  9. Nengo 神经网络
  10. Android计算器简单逻辑实现