Billboard (HDU 2795)
Billboard (HDU 2795)
注意到每个广告的长度是1,因此可以将每这一张广告牌当成一个数列表示,每个初始值为w。使用线段树维护这个数列,每次查询为找到这个数列第一个大于等于x的位置,每次修改操作为将找到的位置值-x
线段树功能:区间查询+单点更新
#include <cstdio>
#include <utility>
#include <queue>
#include <cstring>
#define scan(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define root 1,1,h
using namespace std;
const int Max=2e5+10;
int sum[Max<<2];
int h,w,n;
void Pushup(int rt)
{
sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);
}
void Build(int rt,int l,int r)
{
if(l==r)
{
sum[rt]=w;
return;
}
int mid=(l+r)>>1;
Build(lson);
Build(rson);
Pushup(rt);
}
int Query(int x,int rt,int l,int r)
{
if(l==r)
{
sum[rt]-=x;
return l;
}
int mid=(l+r)>>1,ret;
if(sum[rt<<1]>=x) ret=Query(x,lson);
else ret=Query(x,rson);
Pushup(rt);
return ret;
}
int main()
{
while(~scanf("%d%d%d",&h,&w,&n))
{
if(h>n) h=n;
Build(root);
int x;
for(int i=0;i<n;i++)
{
scan(x);
if(sum[1]<x) printf("-1\n");
else
{
printf("%d\n",Query(x,root));
}
}
}
return 0;
}
Billboard (HDU 2795)的更多相关文章
- Billboard HDU 2795 (线段树)
题目链接 Problem Description At the entrance to the university, there is a huge rectangular billboard of ...
- Billboard HDU - 2795(树状数组,单点修改,区间查询)
题目链接:https://vjudge.net/problem/HDU-2795 思路:h = 1e9行不通,因为广告是1*w的,所以n个广告最多只需要 h = n的高度,那么h=2e5就可以接受了. ...
- HDU 2795 Billboard(线段树的另类应用)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795——Billboard——————【单点更新、求最小位置】
Billboard Time Limit:8000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 2795 Billboard(宣传栏贴公告,线段树应用)
HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意: 要在h*w宣传栏上贴公告,每条公告的高度都是为1的,并且每条公告都要 ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- hdu 2795 Billboard(线段树+单点更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others ...
- HDU 2795 Billboard 【线段树维护区间最大值&&查询变形】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) ...
- HDU 2795:Billboard(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Problem Description At the entrance to th ...
随机推荐
- poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...
- bzoj1036 [ZJOI2008]树的统计Count——LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1036 LCT水题! 然而没有1A(咬牙)! 注意值有负数,所以取 max 的话要把作为“哨兵 ...
- 杂项:game_navigation
ylbtech-杂项:game_navigation 1.返回顶部 1. 2. 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处: ...
- jquery plupload上传插件
http://www.jianshu.com/p/047349275cd4 http://www.cnblogs.com/2050/p/3913184.html demo地址: http://chap ...
- 在Linux环境下使用OpenSSL对消息和文件进行加密(转载)
转自:http://netsecurity.51cto.com/art/201301/378513.htm 1.简介 OpenSSL是一款功能强大的加密工具包.我们当中许多人已经在使用OpenSSL, ...
- bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】
几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...
- bzoj 1653: [Usaco2006 Feb]Backward Digit Sums【dfs】
每个ai在最后sum中的值是本身值乘上组合数,按这个dfs一下即可 #include<iostream> #include<cstdio> using namespace st ...
- VBScript+SCR+NetApi+Accoreconsole 批处理dwg文件
继上次powershell运行accoreconsole(https://www.cnblogs.com/NanShengBlogs/p/10981687.html)的研究之后又觉得不是很合适,毕竟p ...
- 为什么要用Go语言做后端
FMZ数字货币量化平台 www.fmz.com, 后端使用Go语言,这里是创始人Zero谈论使用Go语言所带了的便利.原帖地址:https://www.zhihu.com/question/27172 ...
- golang——database/sql包学习
1.database/sql包 sql包提供了保证SQL或类SQL数据库的泛用接口. 使用sql包时必须注入(至少)一个数据库驱动. (1)获取mysql driver:go get -v githu ...