SKYLINE
uvalive4108:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2109
题意:按照顺序建造一些矩形的房屋,房屋是二维的,每个房屋起点,终点,以及高度给出,然后问你在建造的过程中,所有在建造时候没有被覆盖房屋长度之和。
题解:显然,题目扥意思就是在建造房屋i的时候,在区间x1---x2 之间,比y小或者等于的距离长度。这里就可以用线段树维护。但是要注意,对于此题,要用lazy标记。
lazy==1表示该区间已经被完全覆盖。那么某区间更新的条件就是,1该区间是被完全覆盖的区间,只有一个区间内高度是一致的,才能进行接下来的判断2就是该区间的高度要小于要更新的区间,如果小于则更新,否则直接return。如果不满足条件1,则pushdown();因为只有当lazy==1才被更新,所以这一题在更新的时候不用做标记。lazy的变化,是在pushdown()里面。还有一个重要的地方就是,本题更新的是线段,要处理这个这个问题,别人的做法就是把右端点-1,其实,想想也是有道理的。还有查询的时候,有点变化,可以把更新直接放在查询里面。只要改区间是完全覆盖的,并且要查询的区间在这个范围内,且小于y值,可以直接返回结果,如果大于,直接返回0,如果区间不是完全覆盖,则pushdown。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=; struct Segtree{
int l,r;
int mul,lazy;
inline int mid(){
return (l+r)/;
}
}num[N*];
void build(int rt,int l,int r){
num[rt].l=l;
num[rt].r=r;
num[rt].mul=;
num[rt].lazy=;
if(l==r)
return;
int mid=num[rt].mid();
build(rt<<,l,mid);
build(rt<<|,mid+,r);
} void pushdown(int rt){
if(num[rt].lazy==){
num[rt<<].mul=num[rt].mul;
num[rt<<|].mul=num[rt].mul;
num[rt].lazy=;
}
}
void update(int rt,int l,int r,int val){
if(num[rt].l==l&&num[rt].r==r&&num[rt].lazy==){
if(num[rt].mul<val)
num[rt].mul=val;
return;
}
pushdown(rt);
int mid=num[rt].mid();
if(mid>=r)update(rt<<,l,r,val);
else if(mid<l)update(rt<<|,l,r,val);
else{
update(rt<<,l,mid,val);
update(rt<<|,mid+,r,val);
}
}
int query(int rt,int l,int r,int val){
if(num[rt].lazy==){
if(num[rt].mul<=val){
update(rt,l,r,val);
return r-l+;
}
else return ;
}
pushdown(rt);
int mid=num[rt].mid();
if(mid>=r)return query(rt<<,l,r,val);
else if(mid<l)return query(rt<<|,l,r,val);
else{
return query(rt<<,l,mid,val)+query(rt<<|,mid+,r,val);
}
}
int n;
int main(){
int cas,t1,t2,t3;
scanf("%d",&cas);
while(cas--){
scanf("%d",&n);
build(,,);
int ans=;
for(int i=;i<=n;i++){
scanf("%d%d%d",&t1,&t2,&t3);
ans+=query(,t1,t2-,t3);
}
printf("%d\n",ans);
// scanf("%d",&t1);
}
}
SKYLINE的更多相关文章
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- [地图SkyLine二次开发]框架(5)完结篇
上节讲到,将菜单悬浮到地图上面,而且任何操作都不会让地图把菜单盖住. 这节带大家,具体开发一个简单的功能,来了进一步了解,这个框架. 1.想菜单中添加按钮 -上节定义的mainLayout.js文件里 ...
- [地图SkyLine二次开发]框架(2)
上节讲到,地图加载. 但我们可以发现,当没有页面布局的情况下,<OBJECT>控件,没有占满整个屏幕,这里我们就要用到Extjs的功能了. 这节要讲的是用Extjs为<OBJECT& ...
- [地图SkyLine二次开发]框架(1)
项目介绍: 项目是三维地理信息系统的开发,框架MVC4.0 + EF5.0 + Extjs4.2 + SkyLine + Arcgis,是对SkyLine的二次开发. 项目快结束了,先给大家看一眼效果 ...
- Java for LeetCode 218 The Skyline Problem【HARD】
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- [LA4108]SKYLINE
[LA4108]SKYLINE 试题描述 The skyline of Singapore as viewed from the Marina Promenade (shown on the left ...
- 218. The Skyline Problem *HARD* -- 矩形重叠
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- spring 自定义schema
扩展schema,定义自己的bean属性..不错! 主要: 1,定义META-INF下.xsd文件,这里是people.xsd;定义spring.handlers;定义spring.schemas 2 ...
- 淘宝分布式数据层:TDDL[转]
淘宝根据自己的业务特点开发了TDDL(Taobao Distributed Data Layer 外号:头都大了 ©_Ob)框架,主要解决了分库分表对应用的透明化以及异构数据库之间的数据复制,它是一个 ...
- Java实现平衡二叉树(AVLTree)的构建
近期在学习数据结构上关于平衡二叉树的知识,看了严老师的思路,感觉用java写出递归的构建方式有点困难,由于当中的递归须要把引用传进去,所以感觉是要实现起来比較麻烦,所以就首先想到使用非递归的方式来实现 ...
- iOS-UICollectionView自定义布局
UICollectionView自定义布局 转载: http://answerhuang.duapp.com/index.php/2013/11/20/custom_collection_view_l ...
- short a = 128, byte b = (byte)a 强制类型转换
package 笔试; public class ShortToByte { /** * @param args */ public static void main(String[] args) { ...
- Python之路【第十七篇】:Django【进阶篇】
Python之路[第十七篇]:Django[进阶篇 ] Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接 ...
- MVC ViewEngine视图引擎解读及autofac的IOC运用实践
MVC 三大特色 Model.View.Control ,这次咱们讲视图引擎ViewEngine 1.首先看看IViewEngine接口的定义 namespace System.Web.Mvc { ...
- spring集成 log4j + slf4j
以maven web项目为例, 首先.在pom文件引入相关依赖,如下(spring官网文档有介绍): <dependencies> <!-- spring 相关 --> < ...
- oracle decode函数使用方法
1.decode(V1,1,A,2,B,C) 如果V1=1 那么显示A =2显示B 其他显示C ........ 2. 含义解释: decode(条件,值1,返回值1,值2,返回值2,...值n,返 ...
- Orace数据库锁表的处理与总结<摘抄与总结一>
TM锁(表级锁)类型共有5种,分别称为共享锁(S锁).排它锁(X锁).行级共享锁(RS锁).行级排它锁(RX锁).共享行级排它锁(SRX锁) 当Oracle执行DML语句时,系统自动在所要操作的表上申 ...