题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795

题意:w*h的公告板要贴公告,公告是w*1的,每个公告有先后顺序,要使每个公告贴的位置尽可能地高,问每个公告最高贴多高。不能贴就输出-1。特别“不”需要注意的是,题目给的n数据范围很大,但是n只有200000。所以说可以不用关心h的范围。

线段树叶子节点维护公告板行的剩余宽度,尽可能地往左子树走。更新在查询的时候完成,不要忘记向上更新线段树。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Fread() freopen("in", "r", stdin)
#define Fwrite() freopen("out", "w", stdout)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = (a); i < (n); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Full(a) memset((a), 0w7f7f, sizeof(a)) #define lrt rt << 1
#define rrt rt << 1 | 1
const int mawn = ;
int sum[mawn<<];
int w, h, n, t; void pushUP(int rt) {
sum[rt] = max(sum[lrt], sum[rrt]);
} void build(int l, int r, int rt) {
sum[rt] = w;
if(l == r) return;
int m = (l + r) >> ;
build(l, m ,lrt);
build(m+, r, rrt);
// pushUP(rt);
} void update(int p, int w, int l, int r, int rt) {
if(l == r) {
sum[rt] -= w;
return;
}
int m = (l + r) >> ;
if(p <= m) update(p, w, l, m, lrt);
else update(p, w, m+, r, rrt);
pushUP(rt);
} int query(int l, int r, int rt, int w) {
if(l == r) {
sum[rt] -= w;
// update(l, w, 1, n, 1);
return l;
}
int m = (l + r) >> ;
int ret = sum[rt<<] >= w ? query(l, m, lrt, w) : query(m+, r, rrt, w);
pushUP(rt);
return ret;
} int main() {
// Fread();
while(~scanf("%d%d%d", &h, &w, &n)) {
h = min(h, n);
build(, h, );
while(n--) {
Rint(t);
if(sum[] < t) printf("-1\n");
else printf("%d\n", query(, h, , t));
}
}
return ;
}

[HDOJ2795]Billboard(线段树,单点更新)的更多相关文章

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

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

  2. HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  3. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  4. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  5. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  6. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  8. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

  9. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  10. HDUOJ----1166敌兵布阵(线段树单点更新)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. 帝国cms后台不停的登录成功

    http://bbs.phome.net/showthread-13-305985-1.html 感谢各位的支持与帮助! e/data/adminlogin目录权限没有问题 问题在:计划任务中,刷新自 ...

  2. IIS本地服务器,设置IP地址问题

    IIS启动本地网站的时候,设置了IP地址为本地IP,并绑定特定的端口号,电脑无法打开,但是同个局域网的手机可以打开.

  3. get的四种请求形式

    $_GET变量当用户以get方式请求页面并发送数据的时候,$_GET变量就存储了这些数据——get数据!get请求有4种形式:形式1:<form  action=”abc.php”   meth ...

  4. Interview-Increasing Sequence with Length 3.

    Given an array, determine whether there are three elements A[i],A[j],A[k], such that A[i]<A[j]< ...

  5. Careercup - Facebook面试题 - 6299074475065344

    2014-05-01 01:00 题目链接 原题: Given a matrix with 's. What is the maximum area of the rectangle. In . Ho ...

  6. P2661 信息传递 强连通分量

    题目链接: http://www.luogu.org/problem/show?pid=2661 题解: 这题求最小的单向环. 可因为每个节点初度为1,所以所有的强联通分量都只能是单向环. 所以就是有 ...

  7. 2014 Multi-University Training Contest 3

    官方解题报告http://blog.sina.com.cn/s/blog_a19ad7a10102uyiq.html Wow! Such Sequence! http://acm.hdu.edu.cn ...

  8. C && C++ 内存分配示意图

    <Unix环境系统高级编程>中的C语言内存分布示意图 1.C内存分布 BSS段: 用来存放程序中未初始化的全局变量.BSS是英文Block Started by Symbol的简称.BSS ...

  9. hdu 3807

    很好的思路     枚举有多少人有ipad 判是否满足题目给出的条件 #include <iostream> #include <cstring> #include <c ...

  10. Kafka之ReplicaManager(1)

    基于Kafka 0.9.0版 ReplicaManager需要做什么 Replicated Logs Kafka的partition可以看成是一个replicated log, 每个replica就是 ...