UVA 1232 - SKYLINE(线段树)
UVA 1232 - SKYLINE
题意:按顺序建房。在一条线段上,每一个房子一个高度。要求出每间房子建上去后的轮廓线
思路:线段树延迟更新。一个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(线段树)的更多相关文章
- 2018牛客网暑假ACM多校训练赛(第四场)E Skyline 线段树 扫描线
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round4-E.html 题目传送门 - https://www.no ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVa 1455 Kingdom 线段树 并查集
题意: 平面上有\(n\)个点,有一种操作和一种查询: \(road \, A \, B\):在\(a\),\(b\)两点之间加一条边 \(line C\):询问直线\(y=C\)经过的连通分量的个数 ...
- UVA1232 - SKYLINE(段树部分的变化)
UVA1232 - SKYLINE(线段树区间改动) 题目链接 题目大意:依照顺序盖楼.假设这个位置(当前要盖的楼覆盖范围内)要新建的楼的高度>=之前就有的最大高度,那么就+1.最后输出这个+1 ...
- UVA 11992 Fast Matrix Operations(线段树:区间修改)
题目链接 2015-10-30 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=s ...
- UVA 11983 Weird Advertisement(线段树求矩形并的面积)
UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...
- UVA 12436 - Rip Van Winkle's Code(线段树)
UVA 12436 - Rip Van Winkle's Code option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- UVa 1471 Defense Lines - 线段树 - 离散化
题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...
- uva 11525(线段树)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- mysql查看不同级别的字符集
库的字符集: SELECT default_character_set_name FROM information_schema.SCHEMATA SWHERE schema_name = 'test ...
- update更新另一个字段
1. 写法轻松,更新效率高:update table1 set field1=table2.field1,field2=table2.field2from table2where table1.id= ...
- Java图形界面设计——substance皮肤
http://jianweili007-163-com.iteye.com/blog/1141358 ————————————————————————————————————————————————— ...
- on SDN
sdn (software defined network ) emulex 网络 新型网络创新架构 网络虚拟化的一种实现方式 核心技术:OpenFlow 分离网络设备的控制层面和数据层面 目的:实现 ...
- 取消excel 工作保护 密码的宏
Option Explicit Public Sub AllInternalPasswords() ' Breaks worksheet and workbook structure password ...
- javaweb-Excel导入导出后台代码
前言: 导入导出后台java代码写好很久了,但是...但是...前台不会写啊. 先把后台代码帖上吧 1.excelToDb package util; /** * 代码解释:此方法将传入一个URL,即 ...
- 层层递进——宽度优先搜索(BFS)
问题引入 我们接着上次“解救小哈”的问题继续探索,不过这次是用宽度优先搜索(BFS). 注:问题来源可以点击这里 http://www.cnblogs.com/OctoptusLian/p/74296 ...
- e864. 取的显示器大小尺寸
See also e670 缓冲图像转换为图像. try { Robot robot = new Robot(); // Capture a particular area on the screen ...
- Spring简单集成Redis
- ubuntu下gedit和vim输入中文和中文显示
安装和配置VIM,参考 http://jingyan.baidu.com/album/046a7b3efd165bf9c27fa915.html?picindex=4 在home/你的用户名 这个 ...