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, 如果利用线段树求解的话,很明显 ...
随机推荐
- go每日新闻--2020-02-19
gocn_news_2020-02-19 1.使用 t.Cleanup 做测试收尾 https://ieftimov.com/post/testing-in-go-clean-tests-using- ...
- codewars--js--vowels counting+js正则相关知识
问题描述: Return the number (count) of vowels in the given string. We will consider a, e, i, o, and u as ...
- 传智播客C++视频学习笔记(5)
#include <iostream> using namespace std; void swapInt(int& a, int& b) { int temp = a; ...
- Java中,一个存在了十几年的bug...
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- RabbitMQ工作模式
------------恢复内容开始------------ RabbitMQ基本概念: Producer:生产者(消息的提供者) Consumer:消费者(消息的使用者) Message:消息(程序 ...
- NServiceBus 入门到精通(一)
什么是NServiceBus?NServiceBus 是一个用于构建企业级 .NET系统的开源通讯框架.它在消息发布/订阅支持.工作流集成和高度可扩展性等方面表现优异,因此是很多分布式系统基础平台的理 ...
- 类加载机制与JVM调优命令
一.类加载过程 类加载:类加载器将.class字节码文件加载进Java虚拟机的内存中. 加载:在硬盘上查找并通过IO读入字节码文件 连接:执行校验.准备.解析(可选)步骤 校验:校验字节码文件的正确性 ...
- Lucene之分析器
什么是分析器? 分析(Analysis)在Lucene中指的是将域(Field)文本转换为最基本的索引表示单元—项(Term)的过程. 分析器(Analyzer)对分析操作进行了封装,通过执行一系列操 ...
- for _ in range(n) python里那些奇奇怪怪的语法糖
for _ in range(n)中 _ 是占位符, 表示不在意变量的值 只是用于循环遍历n次. 例如在一个序列中只想取头和尾,就可以使用_ 其实意思和for each in range(n)是一个意 ...
- Python爬虫库BeautifulSoup获取对象(标签)名,属性,内容,注释
这篇文章主要介绍了Pythont特殊语法filter,map,reduce,apply使用方法,需要的朋友可以参考下(1)lambda lambda是Python中一个很有用的语法,它允许你快速定义单 ...