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, 如果利用线段树求解的话,很明显 ...
随机推荐
- C#设计模式学习笔记:(23)解释器模式
本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/8242238.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第十一个模式-- ...
- Linux 用户、用户组管理
Linux系统是一个多用户多任务的分时操作系统,每个用户都有用户名(唯一).口令,用户名唯一标识该用户账号. 用户管理主要涉及到用户添加.修改和删除. 切换用户 su 用户名 su即swit ...
- 阿里Java架构师分享自己的成长经历,教你如何快速成长为架构师
架构师是公司的“金领”,很少需要考虑生存的问题,从而有更多的精力思考关键技术,形成“强者愈强”的良性循环.当然,冰冻三尺非一日之寒,成为一名合格的架构师是一个漫长的积累过程.对于大部分的软件开发人员来 ...
- Linux发行版Ubuntu下的Python开发环境的配置
linux下的Python安装, 首先我们需要使用都Shell一系列的命令(前面的linux基础可不是白学的哦!) 1.更新软件安装源地址 sudo apt-get update apt-get,是一 ...
- (一)LoadRunner安装
1.下载LR,双击exe安装程序,选择LoadRunner完整安装程序,如下图: 2.点击下一步 3.选择我同意,下一步 4.输入姓名和组织(可以不输入),下一步 5.点击浏览选择要安装的目录,建议使 ...
- CSP2019第二轮-划水游记
又是 颓废的 一年 眨眼间已经初三了 到了NOIPCSP的时节 Day0 学校(没错,全校事件)抽风地把二晚停了,于是也就有了机会早早回家van♂耍 和母上大人简单地收拾收拾东西,回了姥姥家 以&qu ...
- go 网络编程
网络编程 tcp 1.tcp客户端服务端实现 server/server.go package main import ( "fmt" "net" ) /* t ...
- 除了降低成本和加速数字化转型,低代码还能给企业带来什么价值 ZT
翻译自:https://dzone.com/articles/measuring-the-roi-of-low-code-1,有删改 低代码 是一种近些年兴起的企业软件快速开发技术和工具.借助低代码使 ...
- API网关服务:Spring Cloud Zuul
最近在学习Spring Cloud的知识,现将API网关服务:Spring Cloud Zuul 的相关知识笔记整理如下.[采用 oneNote格式排版]
- Geographic coordinate systems 坐标系和 wkid
Well-Known ID 与对应的坐标系 地理坐标系 Well-known ID Name Well-known text 3819 GCS_HD1909 GEOGCS["GCS_HD1 ...