poj 3277 City Horizon(线段树#2----离散化)
2012-08-16 11:16
465 查看
需要离散化数据;
219ms
219ms
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define N 100010 typedef long long ll; struct node{ int l, r; int height; }Tree[N * 5]; /// int O; int op [3]; int dat ; void build(int l, int r, int x) { Tree[x].l = l; Tree[x].r = r; Tree[x].height = 0; if (l + 1 == r)return; int mid = (l + r) / 2; build(l, mid, x * 2); build(mid, r, x * 2 + 1); } void update(int l, int r, int val, int x) { if (dat[Tree[x].l] == l && dat[Tree[x].r] == r) { Tree[x].height = max(Tree[x].height, val); return; } int mid = dat[(Tree[x].l + Tree[x].r) / 2]; if (mid <= l)update(l, r, val, x * 2 + 1); else if (mid >= r)update(l, r, val, x * 2); else { update(l, mid, val, x * 2); update(mid, r, val, x * 2 + 1); } } ll find(int faHeight, int x) { Tree[x].height = max(Tree[x].height, faHeight); if (Tree[x].l + 1 == Tree[x].r) { return (ll)(dat[Tree[x].r] - dat[Tree[x].l]) * Tree[x].height; } return find(Tree[x].height, x * 2) + find(Tree[x].height, x * 2 + 1); } int main() { // FILE* fp = fopen("in.txt", "r"); scanf( "%d", &O); int len = 1; for (int i = 0; i < O; i++) { scanf( "%d %d %d", op[i], op[i] + 1, op[i] + 2); dat[len++] = op[i][0]; dat[len++] = op[i][1]; } sort(dat + 1, dat + len); int n = unique(dat + 1, dat + len) - dat - 1; build (1, n, 1); for (int i = 0; i < O; i++) { update(op[i][0], op[i][1], op[i][2], 1); } printf("%lld\n", find(0, 1)); //cout << find(0, 1)<<endl; // getchar(); return 0; }
相关文章推荐
- POJ 3277 City Horizon 扫描线+离散化+线段树
- (离散化 + 线段树) poj 3277 City Horizon
- 离散化+线段树 POJ 3277 City Horizon
- poj-3277-City Horizon-离散化+线段树区域更新
- POJ 3277 City Horizon (离散化线段树)
- poj 3277 City Horizon 线段树加上离散化
- POJ 3277 City Horizon(线段树+扫描线+离散化)
- poj 3277 City Horizon 线段树
- 【POJ 3277】 City Horizon(离散化+树状数组+二分)
- poj 3277(线段树+离散化)
- poj 3277 city horizon 线段树
- poj 3277 City Horizon (线段树 扫描线 矩形面积并)
- Poj 3277 City Horizon - 线段树
- 【线段树】 POJ 3277 City Horizon 裸扫描线
- pku 3277 City Horizon(离散化+线段树)
- 【线段树】 POJ 3277 City Horizon 裸扫描线
- poj 3277...离散化+线段树...
- HDU 3277 City Horizon(线段树 + 离散化)
- #POJ 3277 City Horizon 【离散化、区间更新】
- POJ 3277(离散化,线段树)