Billboard (HDU 2795)

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)的更多相关文章

  1. Billboard HDU 2795 (线段树)

    题目链接 Problem Description At the entrance to the university, there is a huge rectangular billboard of ...

  2. Billboard HDU - 2795(树状数组,单点修改,区间查询)

    题目链接:https://vjudge.net/problem/HDU-2795 思路:h = 1e9行不通,因为广告是1*w的,所以n个广告最多只需要 h = n的高度,那么h=2e5就可以接受了. ...

  3. HDU 2795 Billboard(线段树的另类应用)

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

  4. HDU 2795——Billboard——————【单点更新、求最小位置】

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  5. HDU 2795 Billboard(宣传栏贴公告,线段树应用)

    HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意:  要在h*w宣传栏上贴公告,每条公告的高度都是为1的,并且每条公告都要 ...

  6. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  7. hdu 2795 Billboard(线段树+单点更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others ...

  8. HDU 2795 Billboard 【线段树维护区间最大值&&查询变形】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) ...

  9. HDU 2795:Billboard(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Problem Description   At the entrance to th ...

随机推荐

  1. 清北考前刷题day6早安

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  2. deepin 安装maven

    1.在官网 http://maven.apache.org/download.cgi 下载mvn包   2.新建mvn目录 mkdir  /usr/local/mvn 把压缩包解压到mvn目录下面 修 ...

  3. lnmp环境的nginx的tp5配置

    php7.1 server { listen 80; server_name www.tp5.com; access_log /home/wwwroot/access.log combined; er ...

  4. Visual Studio Code 扩展工具集,记录

    编码 提高效率及校验 Auto Close Tag 自动闭合标签 Auto Rename Tag 自动更改HTML/XML标签,不需要再进行二次修改,减少50%的工作量! Path Intellise ...

  5. [读书笔记3]《C语言嵌入式系统编程修炼》

    第五章 性能优化   5.1 使用宏定义 在C语言中,宏是产生内嵌代码的唯一方法.对于嵌入式系统而言,为了能达到性能要求,宏是一种很好的代替函数的方法.   写一个"标准"宏MIN ...

  6. 树形DP URAL 1039 Anniversary Party

    题目传送门 /* 题意:上司在,员工不在,反之不一定.每一个人有一个权值,问权值和最大多少. 树形DP:把上司和员工的关系看成根节点和子节点的关系,两者有状态转移方程: dp[rt][0] += ma ...

  7. ACM_排序

    除了sort,你还会什么 Time Limit: 1000/500ms (Java/Others) Problem Description: 给出若干人的年龄(1~100之间的整数),把它们按照从小到 ...

  8. Android内存管理(14)*使用开源库LeakCanary检查内存泄漏

    1.简介 它是一个非常简单好用的内存泄漏检测工具库.可以轻松检测Activity,Fragment的内存泄漏.如果有内存泄漏,它会产生一个通知. 2.资料 官网: https://github.com ...

  9. uiautomatorviewer详解

    一,uiautomatorviewer是什么? Android 4.1发布的,uiautomator是用来做UI测试的.也就是普通的手工测试,点击每个控件元素 看看输出的结果是否符合预期.比如 登陆界 ...

  10. Android显示相册图片和相机拍照

    首先看最重要的MainActive类: public class MainActivity extends AppCompatActivity { private final int FROM_ALB ...