对应HDU题目:点击打开链接

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11523    Accepted Submission(s): 5077

Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information.

On September 1, the billboard was empty. One by one, the announcements started being put on the billboard.

Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.

When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.

If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university).

Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed.

Input
There are multiple cases (no more than 40 cases).

The first line of the input file contains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions of the billboard and the number of announcements.

Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement.

Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement.
Sample Input
3 5 5 2 4 3 3 3
Sample Output
1 2 1 3 -1

题意:(别人的~我懒得写)

在大学门口,有一个高位h 宽为w的广告牌,现在广告牌是空的,有一些小的广告要张贴到广告牌上,已知这些小广告的高度都是1,宽为wi,张贴有一定规律,按照顺序来,并且往最高处贴,如果最高处贴不开就往下一行贴,输出每一张广告贴在的行,若果广告牌上贴不开,就输出-1

思路:

将展板90度旋转,即可将长度作为叶子节点,要注意一点:h的范围很大,而题目最多有n次询问!故答案要么是-1,要么不超过n,所以线段数维护的范围是1~min(h,n);

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
const int MAXN=200005*3;//这个我不知道怎样算的,一直试到没有RE,求方法。。。
#define ms(x,y) memset(x,y,sizeof(x))
using namespace std;
int maxn[MAXN];
int ans;
int h,w,n;void buildtree(int rt, int left, int right)
{if(left==right){maxn[rt]=w;return;}int mid=(left+right)>>1;buildtree(rt<<1, left, mid);buildtree(rt<<1|1, mid+1, right);maxn[rt]=max(maxn[rt<<1], maxn[rt<<1|1]);//取叶子结点大的值
}void updata(int rt, int left, int right, int l)
{if(left==right){ans=left;//找到结果!maxn[rt]-=l;//更新长度return;}int mid=(left+right)>>1;if(maxn[rt<<1] >= l) updata(rt<<1, left, mid, l);//先往左走(尽量靠前嘛)else updata(rt<<1|1, mid+1, right, l);//左边不满足则往右走maxn[rt]=max(maxn[rt<<1], maxn[rt<<1|1]);//更新最值
}int main()
{
#if 0freopen("in.txt","r",stdin);
#endifwhile(scanf("%d%d%d", &h,&w,&n)==3){int R=min(h,n);//高度最多取到n,故取小的值就可以了buildtree(1,1,R);while(n--){int l;scanf("%d", &l);if(maxn[1]<l){//如果第一个结点都不满足,就不用算了printf("-1\n");continue;}updata(1,1,R,l);printf("%d\n", ans);}}return 0;
}

线段数单点更新——HDU 2795相关推荐

  1. HDU - 1166敌兵布阵+HDU-1754 I Hate It (线段树单点更新——累加/最大值)

    线段树单点更新,模板题 HDU1166 敌兵布阵 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和T ...

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

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

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

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

  4. 【原创】tyvj1038 忠诚 计蒜客 管家的忠诚 线段树(单点更新,区间查询)...

    [原创]tyvj1038 忠诚 & 计蒜客 管家的忠诚 & 线段树(单点更新,区间查询) 最简单的线段树之一,中文题目,不翻译.... 注释讲的比较少,这已经是最简单的线段树,如果看不 ...

  5. 线段树——单点更新(二)

    HDU 4217 Data Structure? http://acm.hdu.edu.cn/showproblem.php?pid=4217 CZ做的一道题目,我帮忙看了看. 题意:给定N个数(1- ...

  6. FZU 2297 Number theory【线段树/单点更新/思维】

    Given a integers x = 1, you have to apply Q (Q ≤ 100000) operations: Multiply, Divide. Input First l ...

  7. CDOJ 1073 线段树 单点更新+区间查询 水题

    H - 秋实大哥与线段树 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit S ...

  8. FZU 1921 栀子花开 (线段树单点更新)

     Problem 1921 栀子花开 Accept: 300    Submit: 1070 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pro ...

  9. hdu1754(线段树单点更新)

    链接:点击打开链接 题意:在每个测试的第一行,有两个正整数N和M(0<N<=200000,0<M<5000),分别代表学生的数目和操作的数目 学生ID编号分别从1编到N 第二行 ...

最新文章

  1. 证书服务器无法启动,使用 SSL 证书后服务无法启动 - SQL Server | Microsoft Docs
  2. HDU2571:命运(简单dp)
  3. 牛客 - 血压游戏(虚树+dp)
  4. Android之安全退出应用程序的几种方式
  5. 前端学习(1729):前端系列javascript之内容卡片布局
  6. 万用表测线路断点位置_如何测出电线电缆断点在哪?来看看常见的7种方法
  7. dom4j实现为list添加父节点_Heap 堆的实现
  8. 封装 java 1614782839
  9. 李大勇matlab视频解压密码,13.4 环境控制、手动开关模块
  10. 技能拓展笔记-React(一)
  11. 技术随笔八——仰望夜空 仰望Git
  12. int在c语言中的作用,C语言中int,Uint,uint16等有什么区别以及用处
  13. 时空复杂度(时间复杂度/空间复杂度)O(1)、O(n)、O(n^2)、O(log n)、O(n log n)是什么意思,借鉴 然后自己借鉴出来
  14. 青云QingCloud打造云端ICT服务 实现战略全面升级
  15. PyTorch学习—21.GPU的使用
  16. 时间序列预测——ARIMA模型
  17. 计算机电子书 2016 BiliDrive 备份
  18. PDF编辑软件如何编辑PDF文件
  19. 使用JMeter进行接口压力测试
  20. 【逆向工程】 disunity的使用

热门文章

  1. 学生免费领取、配置阿里云服务器
  2. 第12周 oj 汉诺塔问题
  3. 引起电源模块发热的4个主要原因分别是什么?
  4. mac电脑真正好用且实用的软件(不断积累)
  5. XL1509-5.0E1芯片温度为75度。参数12V、0.6A
  6. 威武山上的分配-计蒜客
  7. 二极管专题:几种二极管参数对比
  8. 关于GPIO上拉下拉和高低电平的问题
  9. 三维星座图查询_一种构造通信系统三维星座图的方法
  10. web前端招聘为什么无学历要求?