UVA 1232 - SKYLINE

option=com_onlinejudge&Itemid=8&page=show_problem&category=502&problem=3673&mosmsg=Submission+received+with+ID+13967519" target="_blank" style="">题目链接

题意:按顺序建房。在一条线段上,每一个房子一个高度。要求出每间房子建上去后的轮廓线

思路:线段树延迟更新。一个setv作为高度的懒标记,此外还要在开一个cover表示当前结点一下是否都为同一高度

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) const int N = 100005; int t, n; struct Node {
int l, r, h, setv;
bool cover;
Node() {}
Node(int l, int r) {
this->l = l; this->r = r;
h = 0; setv = 0; cover = true;
}
} node[4 * N]; void pushup(int x) {
node[x].cover = ((node[lson(x)].h == node[rson(x)].h) && node[lson(x)].cover && node[rson(x)].cover);
node[x].h = node[lson(x)].h;
} void pushdown(int x) {
node[lson(x)].setv = max(node[lson(x)].setv, node[x].setv);
node[rson(x)].setv = max(node[rson(x)].setv, node[x].setv);
node[lson(x)].h = max(node[lson(x)].setv, node[lson(x)].h);
node[rson(x)].h = max(node[rson(x)].setv, node[rson(x)].h);
} void build(int l, int r, int x = 0) {
node[x] = Node(l, r);
if (l == r) return;
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
} int query(int l, int r, int v, int x = 0) {
if (node[x].cover && node[x].h > v) return 0;
if (node[x].l >= l && node[x].r <= r && node[x].cover) {
node[x].setv = v;
node[x].h = v;
return node[x].r - node[x].l + 1;
}
int mid = (node[x].l + node[x].r) / 2;
int ans = 0;
pushdown(x);
if (l <= mid) ans += query(l, r, v, lson(x));
if (r > mid) ans += query(l, r, v, rson(x));
pushup(x);
return ans;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
build(1, N - 1);
int l, r, h;
int ans = 0;
while (n--) {
scanf("%d%d%d", &l, &r, &h);
ans += query(l, r - 1, h);
}
printf("%d\n", ans);
}
return 0;
}

UVA 1232 - SKYLINE(线段树)的更多相关文章

  1. 2018牛客网暑假ACM多校训练赛(第四场)E Skyline 线段树 扫描线

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round4-E.html 题目传送门 - https://www.no ...

  2. UVALive - 4108 SKYLINE[线段树]

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

  3. UVa 1455 Kingdom 线段树 并查集

    题意: 平面上有\(n\)个点,有一种操作和一种查询: \(road \, A \, B\):在\(a\),\(b\)两点之间加一条边 \(line C\):询问直线\(y=C\)经过的连通分量的个数 ...

  4. UVA1232 - SKYLINE(段树部分的变化)

    UVA1232 - SKYLINE(线段树区间改动) 题目链接 题目大意:依照顺序盖楼.假设这个位置(当前要盖的楼覆盖范围内)要新建的楼的高度>=之前就有的最大高度,那么就+1.最后输出这个+1 ...

  5. UVA 11992 Fast Matrix Operations(线段树:区间修改)

    题目链接 2015-10-30 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=s ...

  6. UVA 11983 Weird Advertisement(线段树求矩形并的面积)

    UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...

  7. UVA 12436 - Rip Van Winkle&#39;s Code(线段树)

    UVA 12436 - Rip Van Winkle's Code option=com_onlinejudge&Itemid=8&page=show_problem&cate ...

  8. UVa 1471 Defense Lines - 线段树 - 离散化

    题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...

  9. uva 11525(线段树)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. 解析Google集群资源管理系统Omega

    1. 背景 Google的第一代/第二代集群(资源)管理系统被称为Borg,Borg设计细节因零零星星出现在各种文章中而知名,但一直未公开(比如发一篇paper).然而,我们可从腾讯公布的Torca( ...

  2. MySql5.7配置文件my.cnf设置

    # MySql5.7配置文件my.cnf设置[client]port = 3306socket = /tmp/mysql.sock [mysqld]########################## ...

  3. 为HTML5开发人员量身打造的7个Web框架

    HTML5规范开发完成时,将成为主流.据统计2013年全球将有10亿手机浏览器支持HTML5,同时HTML Web开发者数量将达到200万.毫无疑问,HTML5将成为未来5-10年内,移动互联网领域的 ...

  4. 【转】Grafana系列教程–Grafana基本概念

    在上面几篇文章中,我们介绍了Grafana的安装配置以及运行的方法,本篇文章我们就来介绍下Grafana的基本概念. 一.Data Source — 数据源 Grafana支持多种不同的时序数据库数据 ...

  5. WPF ICommandSource Implementations Leak Memory!

    Actually the title of this article should be entitled "How to use WeakEventManager with IComman ...

  6. MinGW下编译openssl, json-c

    目的:在windows环境下,编译开源库openssl 环境:windows 10 ,Mingw及自带msys工具,openssl-1.0.2j 工具主要使用MinGW(含msys1.0), IDE选 ...

  7. Ubuntu16.04安装Mininet

    Ubuntu16.04源码安装Mininet 本文介绍了VMware虚拟机ubuntu16.04中安装Mininet的方法,物理机中的方法与之相同.主要参考了Mininet官方的教程.官方提供了四种安 ...

  8. 【转】]监听SMS消息/编程实现短信拦截

    当设备接收到一条新的SMS消息时,就会广播一个包含了android.provider.Telephony.SMS_RECEIVED动作的Intent.注意,这个动作是一个字符串值,SDK 1.0不再包 ...

  9. SpringCloud微服务部署

    https://blog.csdn.net/weixin_36397925/article/details/79496657 https://blog.csdn.net/forezp/article/ ...

  10. c 二维数组动态分配和释放

    c动态语言 函数声明的头文件在<stdlib.h>里 使用malloc函数为字符串分配内存 -->记得释放内存 free() #include <stdio.h> #in ...