线段树(维护最大值):HDU Billboard
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17190 Accepted Submission(s): 7266
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.
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.
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.
2
4
3
3
3
2
1
3
-1
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int t[maxn<<];
int h,w,n,x; void Build(int node,int l,int r)
{
t[node]=w;
if(l==r)return;
int mid=(l+r)>>;
Build(node<<,l,mid);
Build(node<<|,mid+,r);
} void Query(int node,int l,int r,int q)
{
if(l==r){
printf("%d\n",l);
t[node]-=q;
return;
}
int mid=(l+r)>>,a=node<<,b=a+;
if(t[a]>=q)Query(a,l,mid,q);
else Query(b,mid+,r,q);
t[node]=max(t[a],t[b]);
return;
}
int main()
{
while(~scanf("%d%d%d",&h,&w,&n)){
h=min(n,h);
Build(,,h);
for(int i=;i<=n;i++){
scanf("%d",&x);
if(x>t[])
printf("-1\n");
else
Query(,,h,x);
}
}
return ;
}
线段树(维护最大值):HDU Billboard的更多相关文章
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- hdu 5316 Magician 线段树维护最大值
题目链接:Magician 题意: 给你一个长度为n的序列v,你需要对这个序列进行m次操作,操作一共有两种,输入格式为 type a b 1.如果type==0,你就需要输出[a,b]区间内的美丽序列 ...
- Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)
E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- HDU 6406 Taotao Picks Apples 线段树维护
题意:给个T,T组数据: 每组给个n,m:n个数,m个操作: (对序列的操作是,一开始假设你手上东西是-INF,到i=1时拿起1,之后遍历,遇到比手头上的数量大的数时替换(拿到手的算拿走),问最后拿走 ...
- hdu 5068 线段树维护矩阵乘积
http://acm.hdu.edu.cn/showproblem.php?pid=5068 题意给的略不清晰 m个询问:从i层去j层的方法数(求连段乘积)或者修改从x层y门和x+1层z门的状态反转( ...
- 51nod 1376【线段树维护区间最大值】
引自:wonter巨巨的博客 定义 dp[i] := 以数字 i(不是下标 i)为结尾的最长上升长度 然后用线段树维护 dp[i]: 每个节点维护 2 个信息,一个是当前区间的最大上升长度,一个是最大 ...
- HDU 6155 Subsequence Count 线段树维护矩阵
Subsequence Count Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Oth ...
- hdu 4037 Development Value(线段树维护数学公式)
Development Value Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
随机推荐
- Linux yum命令重装mysql
如果是 rpm 安装的话,可以用 rpm -e mysql-server 如果是yum安装的,可以用 yum remove mysql* 删除MySQL安装文件夹 然后使用yum安装mysql: 1. ...
- HTML5 autocomplete属性、表单自动完成
autocomplete属性 1.定义autocomplete属性规范表单是否启用自动完成功能.自动完成允许浏览器对字段的输入,是基于之前输入的值.2.应用范围autocomplete使用<fo ...
- HTML5 文件域+FileReader 分段读取文件并上传(七)-WebSocket
一.单文件上传实例 HTML: <div class="container"> <div class="panel panel-default" ...
- 一个Socket数据处理模型
Socket编程中,如何高效地接收和处理数据,这里介绍一个简单的编程模型. Socket索引 - SocketId 在给出编程模型之前,先提这样一个问题,程序中如何描述Socket连接? 为什么这么问 ...
- 使用cocoapods管理第三方类库
前言 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正确地配置他们有时候是非常繁琐的事情,幸运的是CocoaPods是一个很好的解决方案. 什么是CocoaPods CocoaPods是OS ...
- 浅析CSS中的haslayout
作为一名web开发人员,最大的希望不是自己的水平有多高,而是希望浏览器厂家能够统一标准,相信任何一个只要是接触过web程序开发的人员都有那样的感受,就是浏览器之间的兼容性问题总是让我们的工作平添诸多的 ...
- cuda中时间用法
转载:http://blog.csdn.net/jdhanhua/article/details/4843653 在CUDA中统计运算时间,大致有三种方法: <1>使用cutil.h中的函 ...
- [LeetCode OJ] Gas Station
问题描述: There are N gas stations along a circular route, where the amount of gas at station i is gas[i ...
- Transpose File
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- Sublime text3 JS语法检测工具安装及使用
Sublime text3 JS语法检测工具安装及使用 工具/原料 sublime text3 nodejs sublimeLinter sublimeLinter-jshint 方法/步骤 首先ct ...