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 ...
随机推荐
- [每日一题] 11gOCP 1z0-052 :2013-09-1 RMAN-- repair failure........................................A20
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/10859315 正确答案:D 一.模拟上题的错误: 1.删除4号文件 [oracle@myd ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- ★ Linked List Cycle II -- LeetCode
证明单链表有环路: 本文所用的算法 能够 形象的比喻就是在操场其中跑步.速度快的会把速度慢的扣圈 能够证明,p2追赶上p1的时候.p1一定还没有走完一遍环路,p2也不会跨越p1多圈才追上 我们能够 ...
- [转] Spring Boot and React hot loader
When I develop web applications, I love using React. I'm also a Spring and groovy addict. Those two ...
- 【转载】ASP.NET支持多语言
ASP.NET 2.0中实现:1.使用工具自动生成本地化资源(LocalResources) 首先建立一个WEB工程,如图所示:双击Default.aspx,切换到[设计]视图,从工具箱里拖一个But ...
- VS 创建 使用C++ 静态类库(Dll)
创建静态类库 Walkthrough: Creating and Using a Dynamic Link Library (C++) 1:菜单栏-->File, New, Project. 2 ...
- c#迭代算法
//用迭代算法算出第m个值 //1,1,2,3,5,8...; //{1,0+1,1+1,1+2,2+3 ,3+5} static void Main(string[] arg ...
- Looper Handler MessageQueue Message 探究
Android消息处理的大致的原理如下: 1.有一个消息队列,可以往队列中添加消息 2.有一个消息循环,可以从消息队列中取出消息 Android系统中这些工作主要由Looper和Handler两个类来 ...
- Premature optimization is the root of all evil.
For all of we programmers,we should always remember that "Premature optimization is the root of ...
- 【读书笔记】管道和FIFO
管道 提供一个单路(单向)数据流,可以为两个不同进程提供进程间的通信手段 #include <unistd.h> ]); 返回两个文件描述符,fd[0](读) 和 fd[1](写) 管道间 ...