Billboard

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

Total Submission(s): 10676    Accepted Submission(s): 4728

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
线段树问题。给出h*w的广告版。每个广告是1*w的,给出m个广告,要每张广告尽量在上层尽量靠左,输出它所在的高度。假设放不下。就输出-1
这里的问题就是h给的非常大,可是 一共仅仅有m个广告,所以即使是一条广告占一条,那么也就仅仅须要m的高度,多余的高度没实用,假设m的高度的不能放下m条广告,那么即使h再高,也放不下,所以n应该是m和h的小值。一段存储下它所控制的区间的最大值,仅仅要最大值大于广告wi,那么第i条广告就能够放到这个区间内。 先推断左子树。左子树不合适后推断右子树,除非是当前的wi大于整段的最大值。否则一定能够放到广告版内,注意,在放入一个广告之后,改动全部的父节点的最大值。
 
 
 
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
#define maxn 300000
#define lmin 1
#define rmax n
#define lson l,(l+r)/2,rt<<1
#define rson (r+l)/2+1,r,rt<<1|1
#define root lmin,rmax,1
#define now l,r,rt
#define int_now int l,int r,int rt
int cl[maxn<<2] , k[maxn<<2] , top ;
void push_up(int_now)
{
cl[rt] = max( cl[rt<<1], cl[rt<<1|1] ) ;
}
void creat(int w,int_now)
{
if( l != r )
{
creat(w,lson);
creat(w,rson);
push_up(now);
}
else
{
cl[rt] = w ;
k[rt] = ++top ;
}
}
int update(int w,int_now)
{
int ans ;
if( cl[rt] < w )
return -1 ;
if( l == r && cl[rt] >= w )
{
cl[rt] -= w ;
return k[rt] ;
}
else
{
if( cl[rt<<1] >= w )
ans = update(w,lson);
else
ans = update(w,rson);
push_up(now);
return ans;
}
}
int main()
{
int i , n , w , m ;
while(scanf("%d %d %d", &n, &w, &m)!=EOF)
{
top = 0 ;
n = min(n,m);
creat(w,root);
while(m--)
{
scanf("%d", &w);
printf("%d\n", update(w,root));
}
}
}

hdu2795Billboard(线段树,找第一个大于w的点)的更多相关文章

  1. W - Doom HDU - 5239 线段树 找取模的规律+求一个很大的数的平方对一个数取模的写法 特别的模数==2^63-2^31

    这个题目一开始感觉还是有点难的,这个模数这么大,根本就不知道怎么写,然后去搜了题解,知道了怎么去求当x很大的时候x的平方对一个数取模怎么样不会爆掉. 然后还顺便发现了一个规律就是当一个数更新一定次数之 ...

  2. hdu2795billboard线段树

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2795/ 题目大意:有一块长方形木板,从上到下被分成h*w的区域,现要将n个长条放进这些区域中,要求从上到下只要后 ...

  3. 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律

    F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...

  4. hdu2795Billboard(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=2795 单点更新,树存储的为某一行内剩余的长度 // File Name: hdu2795.cpp // Auth ...

  5. hdu3436Queue-jumpers(线段树)

    链接 这题最不好求的一部分是rank部分 因为top每次都是把一个数放在队头 不会穿插在数组里 也就是说后面没有top过的一部分数 依旧保持有序 这样可以分为两部分来处理 比如 1 2 3 4 5 6 ...

  6. 『zkw线段树及其简单运用』

    阅读本文前,请确保已经阅读并理解了如下两篇文章: 『线段树 Segment Tree』 『线段树简单运用』 引入 这是一种由\(THU-zkw\)大佬发明的数据结构,本质上是经典的线段树区间划分思想, ...

  7. HDU5692 Snacks DFS序 线段树

    去博客园看该题解 题目 HDU5692 Snacks Problem Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的 ...

  8. 有趣的线段树模板合集(线段树,最短/长路,单调栈,线段树合并,线段树分裂,树上差分,Tarjan-LCA,势能线段树,李超线段树)

    线段树分裂 以某个键值为中点将线段树分裂成左右两部分,应该类似Treap的分裂吧(我菜不会Treap).一般应用于区间排序. 方法很简单,就是把分裂之后的两棵树的重复的\(\log\)个节点新建出来, ...

  9. Codeforces 527C Glass Carving (最长连续0变形+线段树)

    Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...

随机推荐

  1. 页面加载完成触发input[type="file"]控件问题

    由于浏览器厂家的限制,不同的浏览器不开放页面加载完成就允许触发input[type="file"]控件 测试 Chrome .火狐 .IE .微信客户端QQ =>桌面端: C ...

  2. centeros 7开机自动挂载磁盘

    场景: 使用mount命令将新发现的磁盘/dev/sdb挂载给/liu后,但是重启后又看不到磁盘? 问题导致原因: 虽然我们可以使用mount命令去挂载磁盘,但是此操作只对服务器运行期间有效,也就是临 ...

  3. code vs 1245 最小的N个和

    1245 最小的N个和  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 有两个长度为 N 的序列 A ...

  4. 泛泰 A850 4.1.2 刷第三方专用Recovery合集

    下载 http://download.csdn.net/detail/benjaminwan/7406089 专用于刷基于AOSP4.1.2的乐蛙和MIUIV5 由于本人制作的第三方ROM,为了通刷, ...

  5. 怎么样才算是精通 C++?

    C++是一门非常奇妙的语言.让人又爱又恨. 在知乎上看到的一个帖子.怎么样才算是精通C++,这里节选一些精彩的回复. 链接:http://www.zhihu.com/question/20201972 ...

  6. cocos2dx 触摸钢琴

    1.触摸钢琴项目描写叙述 1.1触摸钢琴功能描写叙述 实现手指点按琴键发出相应的音调,按下位置出现星云的粒子特效,滚动实现移动到别的琴键的位置,按下安卓返回键运行关闭. 1.2触摸钢琴所需技术 粒子特 ...

  7. 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记3 Xcode、Auto Layout及MVC

    继续上一话中的计算器Demo.上一话讲到类必须被初始化.类中的属性也必须被初始化,所以你不能仅仅声明而不给它一个处置,那么问题来了,我们从storyboard中拖拽的@IBOutlet为什么仅仅有声明 ...

  8. sass06 mixin

    scss @mixin cont{ //mixin是关键字 color:red; } body{ @include cont; //使用默认值 } @mixin cont($color: red ){ ...

  9. EntityFramework学习笔记1--安装

    1.新建项目 2.工具=>NuGet程序包管理器=>程序包管理控制器 3.PM> Install-Package EntityFramework 安装EF

  10. HBase框架基础(四)

    * HBase框架基础(四) 上一节我们介绍了如何使用HBase搞一些MapReduce小程序,其主要作用呢是可以做一些数据清洗和分析或者导入数据的工作,这一节我们来介绍如何使用HBase与其他框架进 ...