POJ2528Mayor's posters 线段树,离散化技巧
- 题意:一个坐标轴从1~1e7,每次覆盖一个区间(li,ri),问最后可见区间有多少个(没有被其他区间挡住的)
- 线段树,按倒序考虑,贴上的地方记为1,每次看(li,ri)这个区间是否全是1,全是1就说明在它后面贴的把它给挡住了,否则该海报可见。
- 然后就愉快的MLE了。。。。
- 再看看数据范围,离散化如下,比如如果海报的左右端点如下

- 那图中橙色的一块的大小其实对结果没有影响,可以把他们都缩为1


- 最后离散化结果如下图:

- 代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
#define nmax 10010
#define tn t[node]
#define sl (node<<1)
#define sr (1+(node<<1)) using namespace std;
int n;
int inl[nmax],inr[nmax];
struct tin{
int pd,id,num,n2; //0 ->l 1->r
bool operator < (const tin x) const { return x.num>num; }
}in[nmax*];
struct segt { int l,r,v; }t[nmax*]; void build(int node,int l,int r){
tn.l=l;
tn.r=r;
tn.v=;
if(l==r) return;
int mid=(l+r)>>;
build(sl,l,mid);
build(sr,mid+,r);
} int upd(int l,int r,int node,int tv){
int ta=(tv||tn.v);
if(tn.l>=l&&tn.r<=r) tn.v=;
else{
int mid=(tn.l+tn.r)>>;
int tl=,tr=;
if(l<=mid) tl=upd(l,r,sl,tv||tn.v);
if(r>mid) tr=upd(l,r,sr,tv||tn.v);
ta=(tl&&tr)||tv;
tn.v=tn.v||(t[sl].v&&t[sr].v);
}
return ta;
} int main(){
int cas;
cin>>cas;
while(cas--){
cin>>n;
for (int i=; i<n; i++) {
scanf("%d%d",&in[i].num,&in[i+n].num);
in[i].pd=;
in[i+n].pd=;
in[i].id=in[i+n].id=i;
}
sort(in,in+*n);
//离散化
int w=;
in[].n2=(++w);
for (int i=; i<*n; i++) {
if(in[i].num==in[i-].num ) {
in[i].n2=w;
continue;
}
in[i].n2=(++w);
if( in[i].num!=in[i-].num+ ) in[i].n2=(++w);
}
//离散化over
build(,,w);
for (int i=; i<*n; i++) if(in[i].pd) inr[in[i].id]=in[i].n2; else inl[in[i].id]=in[i].n2;
int ans=;
for (int i=n-; i>=; i--) if(upd(inl[i],inr[i],,)==) ans++;
printf("%d\n",ans);
}
return ;
}
POJ2528Mayor's posters 线段树,离散化技巧的更多相关文章
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ2528Mayor's posters[线段树 离散化]
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59683 Accepted: 17296 ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- Mayor's posters (线段树+离散化)
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- Mayor's posters(线段树+离散化POJ2528)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...
- POJ 2528 Mayor's posters (线段树+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
随机推荐
- toj 3019 Hidden Password (最小表示法)
Hidden Password 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交: 53 测试通过: 19 描述 Some time the progr ...
- 跨域打开页面:Uncaught DOMException: Blocked a frame with origin
Uncaught DOMException: Blocked a frame with origin 使用postMessage()方法可以解决跨域传值的问题 Api: https://develop ...
- pikachu-XXE(xml external entity-injection)
部分图片来自于网络,如有侵权,请联系我及时删除~ 一.XXE的概念 1.1 什么是xml xml是一种可拓展的标记语言,可以用来存储数据,例如:我们经常看到一些.xml的文件:它还可以用来传输数据,我 ...
- c语言心形告白代码实现
c语言心形告白代码实现 1.彩色告白 include<stdio.h> include<math.h> include<windows.h> include< ...
- JDK SPI 机制
一.概述 最早看到 SPI 这个机制是在 dubbo 实现 中,最近发现原来也不是什么新东西,竟然就是 JDK 中内置的玩意,今天就来一探究竟,看看它到底是什么玩意! SPI的全称是 Service ...
- vue 使用v-for进行循环
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 10.Android-SharedPreferences使用
1.SharedPreferences介绍 SharedPreferences,它是一个轻量级的配置文件类,用于保存软件配置参数. 采用xml文件形式存储在/data/data/包名/shared_p ...
- 0x01 C语言-编写第一个hello world
学习每一个编程语言都是从 "Hello world!" 开始的,这好像就是编程界一条不成文的规定一样. 在这篇文章中,我将教大家编写一个可以输出 "Hello world ...
- NAS之NFS/CIFS
NAS之NFS 为集群中的 Web Server 配置后端存储 NFS:Network File System 网络文件系统,Unix系统之间共享文件的一种协议NFS 的客户端主要为Linux支持多节 ...
- docker - 如何清理硬盘中无关占用
背景 在使用docker进行容器化管理后会发现本次硬盘文件占用量在不断上升,并且即使是删除掉容器或者镜像也并不能释放掉对应的硬盘空间.本文将提供对应的docker命令用于真正释放掉该部分应被删除释放的 ...