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. UVA 10453 十七 Make Palindrome

    Make Palindrome Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  2. 搭建本地的git仓库

    折腾了快一天了,终于搭建成功了. 分享一下搭建的步骤: 一.GIT仓库的创建 1. adduser git 2. passwd git 此例设置git的密码为123456 3. cd /home/gi ...

  3. Java面试宝典2015版

    这套面试题主要目的是帮助那些还没有java软件开发实际工作经验,而正在努力寻找java软件开发工作的朋友在笔试时更好地赢得笔试和面试.由于这套面试题涉及的范围很泛,很广,很杂,大家不可能一天两天就看完 ...

  4. 屏幕序列Screen Sequences

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

  5. unity3d中asset store 的资源下载到本地的目录位置

    来源:http://blog.csdn.net/fzhlee/article/details/8613688 C:/Users/[当前用户]/AppData/Roaming/Unity/Asset S ...

  6. XAF使用数据库访问层缓存的提升性能

    很多时候,为了提升性能,我们可以给数据库访问层做缓存. 以下几步可以完成这个任务:1. 使用自定义的 XPObjectSpaceProvider1.1. 创建自定义的 XPObjectSpacePro ...

  7. Ext.net 异常统一管理,铥掉可恶的 Request Failure

    Ext.net 异常统一管理,铥掉可恶的 Request Failure 看着这样的框框是不是很不爽 灭他.也不难.. .如果全部页面都有继承一个自定义的父类 ..那整个项目代码量就只有几行了.. 单 ...

  8. servlet文件上传

    1.获取文件上传路径 String path=request.getServletContext.getRePath("/WEB-INF/resources"); 2.获得工厂 3 ...

  9. 没办法,还是要补一下js,回调函数(转载)

    <html> <head> <title>回调函数(callback)</title> <script language="javasc ...

  10. Python学习(1)安装Python

    *****  安装Python 在官网上 https://www.python.org/downloads/ 可以看到有3.5.1与2.7.11两个版本,我这里用的是3.5.1版本 我用的是win7/ ...