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 ...
随机推荐
- 构造Nginx避免直接使用IP通路Webserver
他看上去非常Nginx构造,似乎忽略了ip直接访问Web问题,从理论上讲,这是不利于SEO优化,因此,我们希望能够避免直接使用IP访问该网站,但域名.详细介绍了如何做到这一点,看看下面的. 在官方文件 ...
- QStandardItemModel角色控制及QTreeView加入不同的右键菜单
1.概述 QTreeView最长用的一个功能就是作为导航栏,像vs里的项目结构树,word的文档结构图,资源管理器的文档结构,等等都是利用树形结构组织的,在前面已经讲述了Qt中使用标准化项目模型QSt ...
- U盘安装centos 6.4教程(总算是弄好了
参考:http://blog.chinaunix.net/uid-27666459-id-3342477.html http://www.linuxidc.com/Linux/2011-05/3569 ...
- javascript 高级程序设计(二)-在html中使用javascript
<script> async 可选 charset 可选 defer 可选 language 已废弃 src 可选 type 可选
- Eclipse / Android : “Errors running builder 'Android Pre Compiler' on project…”
Errors occurred during the build. Errors running builder 'Android Resource Manager' on project 'hell ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 二进制编码的个体解码操作 decode.c
种群解码函数 decode_pop 为包装函数, 核心调用函数为 decode_ind , 对每个个体进行解码. /* Routines to decode the population */ ...
- jQuery注册验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- My-sql #1045 - Access denied for user 'root'@'localhost' (using password: NO)
当你重装数据库后出现这个问题的时候,不要着急,首先你要去你的确定你的数据库已经成功的把服务开启了, 然后确定你的密码和账户,IP都确认的情况下, 去寻找config.inc.php 这个文件,根据配置 ...
- Echarts使用随笔(1)-Echarts中markPoint的使用(静态、动态)-effect
先看一段关于初始化Echart js的使用 myChart = echarts.init(document.getElementById('mainChart')); var o ...
- SQL Server 表字段值转换成字段名称(二)
上次写了个比较简单的只有两个字段的例子,经要求在写个 3 个字段的示例 ,贴上来与大家共勉一下 如果你们有更好的方法,提供一下, 感激不尽. 示例如下: /*--drop table temp_ ...