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的更多相关文章

  1. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. [LeetCode] The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  4. [地图SkyLine二次开发]框架(5)完结篇

    上节讲到,将菜单悬浮到地图上面,而且任何操作都不会让地图把菜单盖住. 这节带大家,具体开发一个简单的功能,来了进一步了解,这个框架. 1.想菜单中添加按钮 -上节定义的mainLayout.js文件里 ...

  5. [地图SkyLine二次开发]框架(2)

    上节讲到,地图加载. 但我们可以发现,当没有页面布局的情况下,<OBJECT>控件,没有占满整个屏幕,这里我们就要用到Extjs的功能了. 这节要讲的是用Extjs为<OBJECT& ...

  6. [地图SkyLine二次开发]框架(1)

    项目介绍: 项目是三维地理信息系统的开发,框架MVC4.0 + EF5.0 + Extjs4.2 + SkyLine + Arcgis,是对SkyLine的二次开发. 项目快结束了,先给大家看一眼效果 ...

  7. 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 ...

  8. The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  9. [LA4108]SKYLINE

    [LA4108]SKYLINE 试题描述 The skyline of Singapore as viewed from the Marina Promenade (shown on the left ...

  10. 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 ...

随机推荐

  1. 在RichTextBox控件中插入图片

    . 在RichTextBox控件中插入图片 关键点 . 实现过程 .   public void ShowInsertImageDlg() {     OpenFileDialog OpenFileD ...

  2. Python3.x爬虫教程:爬网页、爬图片、自己主动登录

    林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 摘要:本文将使用Python3.4爬网页.爬图片.自己主动登录.并对HTTP协议做了一个简单 ...

  3. android 17 activity生命周期

    手机指南针传感器处于手机头部. Activity生命周期: 启动. onCreat()方法:初始化布局对象,设置监听器. onstart()方法:注册监听器. onResume():activity已 ...

  4. [转] webpack debug in webstorm

    先run build,然后用node server.js来做 WebStorm 11 adds support for debugging client-side apps built with We ...

  5. [转] Linux抓包工具tcpdump详解

    http://www.ha97.com/4550.html PS:tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使 ...

  6. Winform 程序中dll程序集嵌入exe可执行文件

    关于这方面,Google一下有很多方法,参考: http://blog.csdn.net/astonqa/article/details/7300856 但按照以上的方法我并没有成功,于是继续找到了一 ...

  7. Android 使用弹出对话框,报Unable to add window错误

    今天在使用Android弹出对话框的时候,报了一个unable to add window错误,我的代码如下 new AlertDialog.Builder(getApplicationContext ...

  8. How to Make LastPass Even More Secure with Google Authenticator

    Google Authenticator LastPass supports Google Authenticator, which is officially available as an app ...

  9. head标签

    1.head标签中有个<meta>,,个人理解知识,可以设置页面字符集,文本格式,还可以加一些注释,例如如下所示

  10. IE6解决固定定位代码

    有些朋友在进行网页布局时,会遇到IE6浏览器不支持固定定位的兼容性问题,本博将详细介绍此问题的解决方法,需要了解的朋友可以参考下. ie6 垂直居中固定定位,代码如下: #center {_posit ...