UVA 1232 - SKYLINE(线段树)
来源:互联网 发布:小批量梯度下降算法 编辑:程序博客网 时间:2024/05/18 11:33
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;}
2 0
- UVA 1232 - SKYLINE(线段树)
- uva 1232 - SKYLINE(线段树)
- UVA 1232 Skyline (线段树)
- UVA 1232 - SKYLINE(线段树区间更新)
- UVa 1232 SKYLINE (线段树区间修改)
- 【UVA】1232 - SKYLINE(线段树减枝)
- SKYLINE uva+线段树+区间的修改+lazy标记
- UVa 105|The Skyline Problem|暴力|线段树
- uva1232 - SKYLINE 线段树
- UVa:1232 SKYLINE
- Uva 1232 SKYLINE
- UVA 1232 - SKYLINE
- UVA 1232 - SKYLINE
- LA 4108 SKYLINE 线段树
- UVA1232,LA4108,Skyline,线段树
- 【UVALive】4108 SKYLINE 线段树
- UVaLive 4108 - SKYLINE (线段树)
- UVA1232 - SKYLINE(线段树区间修改)
- 91_采用绑定服务的方式调用服务里面的方法
- file
- Java中static、final用法小结
- C语言实型(小数)
- HDU 1260 Tickets (动规)
- UVA 1232 - SKYLINE(线段树)
- 深入理解CSS盒子模型 - The CSS Box Model
- Linux之nohup命令
- POJ 2186 Popular Cows (强连通 出度)
- POJ 2395 Prim
- 网络流dinic模板更新...
- namenode和jobTracker进程没起来的原因
- java httpURL连接远程服务器并返回数据(httpurlconnection)
- 黑马程序员_java入门之java基础常识与jiava环境搭建