POJ 2528 Mayor's posters (线段树区间更新、离散化)
来源:互联网 发布:福州 数据分析 培训 编辑:程序博客网 时间:2024/05/01 16:00
题目链接:http://poj.org/problem?id=2528
题意:题目大意:在墙壁上贴广告,广告的版面有大有小,并且贴广告有先后之分,后面贴的广告会覆盖前面的广告,求解最后能看到的广告面,如下图所示:
两种视图,最后从Front View能看见的广告数目是4。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;struct node{int l, r, m;ll val;};const int maxn = 10010;node T[maxn << 4];int col[maxn];int ans;void pushdown(int rt) {if(T[rt].val != -1) { T[rt << 1].val = T[rt].val; T[rt << 1 | 1].val = T[rt].val; T[rt].val = -1; }}void build(int begin, int end, int rt) {T[rt].l = begin;T[rt].r = end;T[rt].m = (T[rt].l + T[rt].r) >> 1;T[rt].val = -1;if(begin == end) return ;build(T[rt].l, T[rt].m, rt << 1);build(T[rt].m + 1, T[rt].r, rt << 1 | 1);}void update(int L, int R, int num, int rt) {if(L == T[rt].l && T[rt].r == R) {T[rt].val = num;return ;}pushdown(rt);if(L > T[rt].m) update(L, R, num, rt << 1 | 1); else if(R <= T[rt].m) update(L, R, num, rt << 1); else { update(L, T[rt].m, num, rt << 1); update(T[rt].m + 1, R, num, rt << 1 | 1); } }void query(int rt) {if(T[rt].val != -1) {if(!col[T[rt].val]) ans++;col[T[rt].val] = 1;return ;}if(T[rt].l == T[rt].r) return ;query(rt << 1);query(rt << 1 | 1);}int x[maxn<<2], top;pair<int, int> q[maxn];int main() {int t;scanf("%d", &t);int n;int tl, tr;while(t--) {top = 0;scanf("%d", &n);for(int i = 0; i < n; i++) {scanf("%d %d", &q[i].first, &q[i].second);x[top++] = q[i].first;x[top++] = q[i].second;}sort(x, x + top);int m = 1;for(int i = 1; i < top; i++) {if(x[i] != x[i - 1]) x[m++] = x[i];}for(int i = m - 1; i > 0; i--) {if(x[i] - 1 != x[i - 1]) x[m++] = x[i] - 1;}sort(x, x + m);build(0, m, 1);for(int i = 0; i < n; i++) {int l = lower_bound(x, x + m, q[i].first) - x;int r = lower_bound(x, x + m, q[i].second) - x;update(l, r, i, 1);}memset(col, 0, sizeof col);ans = 0;query(1);printf("%d\n", ans);}return 0;}
0 0
- POJ 2528-Mayor's posters(线段树区间更新+离散化)
- POJ 2528 Mayor's posters (离散化+线段树区间更新)
- poj 2528 Mayor's posters(线段树 离散化 区间更新 贴海报)
- Poj 2528 Mayor's posters (线段树区间更新+离散化)
- poj 2528 Mayor's posters(线段树 二分 大数据离散化 区间更新)
- POJ 2528 Mayor's posters (线段树区间更新、离散化)
- POJ 2528 Mayor's posters (线段树 区间更新+离散化)
- Mayor's posters(线段树区间更新+离散化)
- Mayor's posters (线段树+离散化+区间更新)
- POJ 2528 Mayor's posters 区间离散化线段树
- poj 2528 Mayor's posters(线段树+区间离散化)
- poj 2528 Mayor's posters (线段树+区间离散)
- 线段树区间更新,区间统计+离散化 POJ 2528 Mayor's posters
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
- POJ 2528 Mayor's posters(区间更新 + 离散化)
- poj 2528 Mayor's posters 线段树+离散化 区间更新
- poj 2528 Mayor's posters(线段树区间更新+离散化)经典题目,较难。。。
- POJ 2528 Mayor's posters 线段树离散化+区间更新
- 回来就是开始——发布计划
- C 停车场管理系统
- Linux库的搜索路径
- 文章标题
- numpy array的细微差别,不仔细还真看不出
- POJ 2528 Mayor's posters (线段树区间更新、离散化)
- 为什么没有javax.servlet.http的引用
- VS2012 error C2065: “bitmap1”: 未声明的标识符;
- 水,,
- 拓扑排序(topological sort)
- @RequestBody, @ResponseBody 注解详解
- 智慧北京:轮播触摸控制
- AVL树的简单实现
- mysql查询今天、昨天、7天、近30天、本月、上一月 数据