hdu 2795 线段树
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.
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.
#include <iostream> using namespace std; const int N = 1e6+10; const int maxh = 4*N; struct node { int l; //左边界 int r; // 右边界 int val, lazy; //节点所维护的区间[l, r]的权值, 懒惰标记 }t[maxh];//N为总节点数 //int val[maxh]; //原数组 int h,w,n; void pushup(int n) { t[n].val = max(t[2*n].val,t[2*n+1].val); //总区间和 = 左区间和+右区间和 } void build(int n,int l,int r) { t[n].l = l; //记录维护的原数组的左端点 t[n].r = r; //记录维护的右端点 t[n].lazy = 0; //标记下懒惰数组 if(l==r){ //l==r,表示叶子节点, t[n].val = w; //因为l==r,那么这个节点维护的值就是原数组val[l]的值 return; } int mid = (l+r)>>1; build(n*2,l,mid); //递归建左子树 build(n*2+1,mid+1,r); //递归建左子树 pushup(n); //求该点的权值 } void updateOne(int n,int C) { int l = t[n].l;//左端点 int r = t[n].r;//右端点 if(l==r) //l==r,到了叶子节点 { printf("%d\n",l); t[n].val -= C; //更新权值 return; } if( t[2*n].val>=C ) //val[idx]由左节点维护 updateOne(n*2,C); else //val[idx]由右节点维护 updateOne(n*2+1,C); pushup(n); //向上更新 } int main() { while(~scanf("%d%d%d",&h,&w,&n)){ if(h>n) //小坑 h=n; build(1,1,h); int ww; for(int i=1;i<=n;i++){ scanf("%d",&ww); //cout<<" "<<t[1].val<<endl; if(t[1].val>=ww) updateOne(1,ww); else puts("-1"); } } return 0; }
原文地址:https://www.cnblogs.com/lyj1/p/11897068.html
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Vue.js 教程:构建一个特斯拉汽车余电计算器
- 文件系统:隐匿在 Linux 背后的机制
- MySQL在Docker环境下运行基础
- Redis 秒杀实战
- Oracle 19c集群重装步骤详解
- 神经网络训练中回调函数的实用教程
- DGA域名检测的数据分析与深度学习分类
- Saferwall:下一代开源恶意软件分析平台
- Java安全编码之SQL注入
- Wireshark解密HTTPS流量
- 独家 | 如何用XGBoost做时间序列预测?
- 关于Web点击劫持的一些实例
- LeetCode 爬取官网所有题目和自己的最近题解
- 一张图实现3D人脸建模!这是中科院博士生入选ECCV的新研究 | 开源
- client-go 之 DeltaFIFO 实现原理