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 ...
随机推荐
- 昆石VOS3000_2.1.3.2完整安装包及安装脚本
安装包下载地址:http://www.51voip.org/post/55.html 安装教程: 上传安装包 核实 关闭selinux 是否关闭 /usr/sbin/sestatus -v cd /r ...
- 使用IntelliJ IDEA 创建Maven项目(入门)
一. 下载Maven 下载地址:http://maven.apache.org/download.cgi tar.gz压缩格式用于unix操作系统,而zip用于windows的操作系统,但在windo ...
- 清北考前刷题day7早安
- P3626 [APIO2009]会议中心
传送门 好迷的思路-- 首先,如果只有第一问就是个贪心,排个序就行了 对于第二问,我们考虑这样的一种构造方式,每一次都判断加入一个区间是否会使答案变差,如果不会的话就将他加入别问我正确性我不会证 我们 ...
- 分布式消息通信(ActiveMQ)
分布式消息通信(ActiveMQ) 应用场景 异步通信 应用解耦 流量削峰 # ActiveMQ安装 下载 http://activemq.apache.org/ 压缩包上传到Linux系统 apac ...
- 键盘按钮keyCode大全:获取按键对应的键值的方法
没有大全,只有方法,授人与鱼不如授人于渔: 下面这行代码,大家可以打在控制台里,直接进行测试: document.body.onkeyup = function (e) { e = e || wind ...
- daily_journal_3 the game of thrones
昨晚追完了最爱的美剧(the game of thrones),哇,看到结局有点崩溃.果然还是美帝淫民开放,各种乱伦,在七夕收到的万点暴击就祝天下有情人就像剧中一样终是血亲. 昨天算是完成了git的复 ...
- 向Linus学习,让代码具有good taste
在最近关于 Linus Torvalds 的一个采访中,这位 Linux 的创始人,在采访过程中大约 14:20 的时候,提及了关于代码的 “good taste”.good taste?采访者请他展 ...
- Selenium示例集锦--常见元素识别方法、下拉框、文本域及富文本框、鼠标操作、一组元素定位、弹窗、多窗口处理、JS、frame、文件上传和下载
元素定位及其他操作 0.常见的识别元素的方法是什么? driver.find_element_by_id() driver.find_element_by_name() driver.find_ele ...
- Android基础TOP6_2:Gallery +Image完成画廊
Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...