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, 如果利用线段树求解的话,很明显 ...
随机推荐
- MySQL常用关键词
MySQL常用关键词 1. 显示表departments的结构:DESC DESC departments; 2. 显示出表employees中的全部job_id(不能重复):DISTINCT SE ...
- C语言中的弱符号(weak)用法及实例
一 符号概念: 在C语言中,有强符号和弱符号,符号简单来说就是函数.变量的名字,对于全局(非局部.非static)的函数和变量,能不能重名是有一定规矩的,强.弱符号就是针对这些全局函数和变量来说的. ...
- ACM 英文学习系列
因为ACM题目描述全是英文,所以有必要学习学习相关词汇...内心极为无奈 废话不多说 rooted binary tree 有根二叉树 integers n 英[ˈɪntɪdʒəz] 整数 ...
- Java架构师必看,超详细的架构师知识点分享!
在Java程序员行业中,有不少Java开发人员的理想是成为一名优秀的Java架构师,Java架构师的主要任务不是从事具体的软件程序的编写,而是从事更高层次的开发构架工作.他必须对开发技术非常了解,并且 ...
- centos配置网络yum源 和本地yum源
一,网络yum源 1.备份 yum文件 cd /etc/ cp -r yum.repos.d yum.repos.d.bak 2.在系统联网的情况下执行下面命令下载 wget -O /etc/yu ...
- 【Android】Retrofi的基础使用教程
文章参考学习自 阳光沙滩 ,是我在B站上发现的宝藏Up主,超级棒! 在前段时间我写了一个java web后台,想做一个安卓端的打卡社区,后来发现请求和解析过于麻烦,就耽搁了. 趁着空闲,研究了一下大部 ...
- python3练习100题——002
因为特殊原因,昨天没有做题.今天继续- 原题链接:http://www.runoob.com/python/python-exercise-example2.html 题目: 企业发放的奖金根据利润提 ...
- nCompass-解决方案介绍
nCompass-解决方案介绍 1. IT运维的现状及痛点 业务部门投诉系统不可用,各个部门盘查: 网络是通的:系统资源正常:应用进程状态都是正常的:数据库日志中也没有报错 运维被动: 80%的故障 ...
- ECMAScript 6基础
ECMAScript 和 JavaScript 是什么关系? 1996 年 11 月,JavaScript 的创造者 Netscape 公司,希望JavaScript能够成为国际标准,将其提交给标准化 ...
- 一些实用的GitHub项目
原文链接:http://www.louisvv.com/archives/2036.html 最近整理了一些在GitHub上比较热门的开源项目 关于GitHub,快速了解请戳这里 其中涵盖了:学习教程 ...