poj2528 Mayor's posters(线段树区间覆盖)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 50888 | Accepted: 14737 |
Description
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
Output
The picture below illustrates the case of the sample input. 
Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4 离散化比较重要,如果两个点差值大于一,那么他们之中应该有空出来的区间,那么在他们之间加入一个点;但是如果差值为一,那么就不用在其中加点,因为他们之中并没有区间
只有这样(1, 10), (1, 6), (8, 10) 这样6和8之间,只有加点才会使7被考虑在内
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int xx[], yy[];
int sor[], cnt, deal[], col[];
int ans, vis[];
int hi;
void hash() {
int last = sor[];
hi = ;
memset(deal, , sizeof(deal));
deal[++hi] = last;
for (int i = ; i <= cnt; i++ ) {
if (sor[i] == last) continue;
if (sor[i] - last > ) deal[++hi] = last + , deal[++hi] = sor[i], last = sor[i];
else deal[++hi] = sor[i], last = sor[i];
}
sort(deal + , deal + + hi);
return;
}
int Bsearch(int x) {
int low = , high = hi;
while (low <= high) {
int mid = low + high >> ;
if (deal[mid] == x) return mid;
if (deal[mid] < x) low = mid + ;
else high = mid - ;
}
return -;
}
void Push_down(int o) {
if (col[o] != -) {
col[o << ] = col[o << | ] = col[o];
col[o] = -;
}
}
void query(int o, int l, int r) {
if (col[o] != -) {
if (!vis[col[o]]) ans++;
vis[col[o]] = true;
return;
}
if (l == r) return;
int mid = (l + r) >> ;
query(o << , l, mid);
query(o << | , mid + , r);
}
void update(int o, int l, int r, int ql, int qr, int v) {
if (ql <= l && r <= qr) {
col[o] = v;
return;
}
Push_down(o);
int mid = (l + r)>> ;
if (ql <= mid) update(o << , l, mid, ql, qr, v);
if (qr > mid) update(o << | , mid + , r, ql, qr, v);
}
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
ans = ;
scanf("%d", &n);
cnt = ;
memset(sor, , sizeof(sor));
for (int i = ; i <= n; i++) {
scanf("%d%d", &xx[i], &yy[i]);
sor[++cnt] = xx[i], sor[++cnt] = yy[i];
}
sort(sor + , sor + cnt + );
hash();
memset(col, -, sizeof(col));
for (int i = ; i <= n; i++) {
int ql = Bsearch(xx[i]), qr = Bsearch(yy[i]);
update(, , hi, ql, qr, i);
}
memset(vis, , sizeof(vis));
query(, , hi);
printf("%d\n", ans);
}
return ;
}
poj2528 Mayor's posters(线段树区间覆盖)的更多相关文章
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- poj2528 Mayor's posters(线段树区间修改+特殊离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- Mayor's posters 线段树区间覆盖
题目链接 http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that t ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
随机推荐
- android apk jarsigner 签名打包
cmd 命令符打包: 规则: jarsigner -verbose -keystore 签名路径 -signedjar 签名后的apk存放路径 未签名的apk 签名文件的别名 项目如我的项目是: ...
- Stem Cell 华人科学家
Jianping Fu 密歇根大学机械工程系生物医学工程专业 PhD, Massachusetts Institute of Technology, 2007MS, University of Cal ...
- springMVC拦截器简单配置
<!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor> <!-- 拦截所 ...
- opencv 相关一个很好的博客
http://blog.csdn.net/zouxy09/article/category/1218765 图像卷积与滤波的一些知识点 图像卷积与滤波的一些知识点zouxy09@qq.comhttp: ...
- Java的SSH框架
SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架. 1.业务流程 集成SSH框架的系统从职责上分为四层:表示层.业务逻辑层.数据 ...
- JavaScript window.setTimeout() 的详细用法
setTimeout (表达式,延时时间)setTimeout(表达式,交互时间) 延时时间/交互时间是以豪秒为单位的(1000ms=1s) setTimeout 在执行时,是在载入后延迟指定时间后, ...
- 【转】获取/设置IFRAME内对象元素的几种JS方法
1.IE专用(通过frames索引形象定位): document.frames[i].document.getElementById('元素的ID'); 2.IE专用(通过IFRAME名称形象定位): ...
- 剑指offer替换空格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- Memcached函数整理
public bool Memcached::add ( string $key , mixed $value [, int $expiration ] ) 向key中添加值,如果key存在,返回f ...
- rpm命令说明
RPM命令常用参数 RPM的常规使用方法为rpm-?package.rpm,其中-?为操作参数(更多信息,请查阅帮助$manrpm): -q在系统中查询软件或查询指定rpm包的内容信息-i在系统中安装 ...