题目链接: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. cocos2dx中的触摸事件及触摸优先级

    1.只有CCLayer及其派生类才有触摸功能. 2.开启触摸 setTouchEnable(true); 3.设置触摸模式,单点,多点(仅IOS支持) setTouchMode(kCCTouchesO ...

  2. How does java technology relate to cloud computing?

    Java Paas shootout   (@IBM developer) Cloud computing is always a hot topic around IT field today.Ho ...

  3. PDF.NET框架操作——工具应用(一)

    PDF.NET是个开源的项目其解决UI层(WinForm / Web)控件数据绑定.映射与查询: BLL层实体对象查询(OQL):DAL层SQL语句和.NET数据访问代码映射(查看  SQL-MAP ...

  4. python 获取文件大小,创建时间和访问时间

    # -*- coding: UTF8 -*- import timeimport datetime import os 1. '''把时间戳转化为时间: 1479264792 to 2016-11-1 ...

  5. BZOJ 3436: 小K的农场 差分约束

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=3436 题解: 裸的差分约束: 1.a>=b+c  ->  b<=a-c ...

  6. ZendStudio中设置SVN:ignore

    使用ZendStudio开发SVN中的代码时,经常容易将 .project..settings..buildpath 这类的zend的工程文件提交上去,非常麻烦,有几种方法可以去掉这个麻烦. 1.在Z ...

  7. ${fn:length(worklicenseList)} #表示不在struts堆栈里,没有#表示从struts堆栈里取

    ${fn:length(worklicenseList)} #表示不在struts堆栈里,没有#表示从struts堆栈里取

  8. linux源代码阅读笔记 fork和execve的区别

    1. man exec就可以知到: The exec() family of functions replaces the current process image with a new proce ...

  9. C#和Javascript中 正则表达式使用的总结

    说明:本文并非原创,而是从网站上搜集了一些资料整理的!如有雷同,纯属巧合 1.js中正则表达式的使用 在js中定义正则表达式很简单,有两种方式,一种是通过构造函数,一种是通过//,也就是两个斜杠.例如 ...

  10. 移动开发之meta篇

    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable= ...