Billboard

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

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
 
Author
hhanger@zju
 
Source

代码:     代码写的比较脆,花掉的时间是:3795ms 呵~~呵~~ ,呵了个呵的!

 /*基础的线段树*/
#include<cstdio>
#include<cstring> const int maxn= ;
int aa[maxn]; struct node
{
int lef,rig,mx;
int mid(){
return lef+((rig-lef)>>);
}
}; int h,w,n;
node reg[maxn<<];
inline int max(int a,int b)
{
return a>b?a:b;
} void Build(int lef,int rig,int pos)
{
reg[pos]=(node){lef,rig,w};
if(lef==rig) return ;
int mid=reg[pos].mid();
Build(lef,mid,pos<<);
Build(mid+,rig,pos<<|);
} void Work(int val,int pos)
{
if(reg[pos].mx>=val)
{
if(reg[pos].rig==reg[pos].lef)
{
reg[pos].mx-=val;
printf("%d\n",reg[pos].rig);
return ;
}
if(val<=reg[pos<<].mx)
Work(val,pos<<);
else
Work(val,pos<<|);
reg[pos].mx=max(reg[pos<<].mx,reg[pos<<|].mx);
}
else if(pos==) printf("-1\n");
return ;
} int main()
{
int cn;
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
if(h>n) h=n;
Build(,h,);
while(n--)
{
scanf("%d",&cn);
Work(cn,);
}
}
return ;
}

HDU-------(2795)Billboard(线段树区间更新)的更多相关文章

  1. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  2. HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  3. [HDU] 2795 Billboard [线段树区间求最值]

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

  4. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  5. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  6. ACM学习历程—HDU 2795 Billboard(线段树)

    Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...

  7. HDU 2795 Billboard 线段树,区间最大值,单点更新

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

  8. HDU 2795 Billboard (线段树+贪心)

    手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...

  9. HDU 2795 Billboard (线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告;   然后给n个1*wi的广告,要求把广告贴 ...

  10. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

随机推荐

  1. <转>32位移植到64位 注意事项

    32bit-64bit porting work注意事项 64位服务器逐步普及,各条产品线对64位升级的需求也不断加大.在本文中,主要讨论向64位平台移植现有32位代码时,应注意的一些细小问题. 什么 ...

  2. [SAP ABAP开发技术总结]BAPI调用

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. [SAP ABAP开发技术总结]内表操作

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. CUBRID学习笔记 41 sql语法之select

    cubrid的中sql查询语法 SELECT [ ] [{TO | INTO} ][FROM ] [WHERE ][GROUP BY {col_name | expr} [ASC | DESC], . ...

  5. 没有Path的Binding

    当Binding源本身就是数据且不需要Path来指明时,可以设置Path的值为".",或直接省略Path.XAML中这个"."可以省略不写,但在C#代码中是不能 ...

  6. JS学习笔记(一) 概述

    参考资料: 1. http://www.w3school.com.cn/js/ 2. http://www.liaoxuefeng.com/wiki/001434446689867b27157e896 ...

  7. sgu-508 Black-white balls 概率-贝叶斯公式

    题意:有n个球,其中有0.1.2...n个黑球的概率是相等的,现在从中取出L个球,p个黑球q个白球.现在问猜一个黑球的区间,使得落在这个区间的概率大于给定的一个数值. 详见代码: #include & ...

  8. XMLHttpRequest对象进行Ajax操作

    XMLHttpRequest 对象的三个常用的属性: 1. onreadystatechange 属性  onreadystatechange 属性存有处理服务器响应的函数. 请求状态改变的事件触发器 ...

  9. (二)再议MII、RMII、GMII接口

    概述:         MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC ...

  10. mybatis动态SQL中的sql片段

    在mybatis中通过使用SQL片段可以提高代码的重用性,如下情景: 1.创建动态SQL <sql id="sql_count">select count(*)< ...