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, 如果利用线段树求解的话,很明显 ...
随机推荐
- NCE L3
单词 课文
- ORB-SLAM2 论文&代码学习 —— LoopClosing 线程
转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12369339.html 本文要点: ORB-SLAM2 LoopC ...
- java开发学生信息管理系统 源码
开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MYSQL数据库 运行效果图 源码及原文链接:https://javadao.xyz/forum.php?mo ...
- powersploit的两个信息收集的脚本
0x00 简介 powersploit是基于powershell的渗透工具包,里面都是powershell的脚本工具文件.工具包地址:https://github.com/PowerShellMafi ...
- Mac下搭建selenium环境
1,安装selenium 打开terminal,使用以下命令安装selenium: pip install -U selenium 2,下载chromedriver,并放在python的安装根目录 ...
- java代码生成器 快速开发平台 二次开发 外包项目利器 springmvc SSM后台框架源码
. 权限管理:点开二级菜单进入三级菜单显示 角色(基础权限)和按钮权限 角色(基础权限): 分角色组和角色,独立分配菜单权限和增删改查权限. 按钮权限: 给角色分配按钮权限.2 ...
- 第2章 在 HTML中 使用 JavaScript
第2章 在 HTML中 使用 JavaScript 2.1 script 元素 2.1.1 标签的位置 2.1.2 延迟脚本 2.1.3 异步脚本 2.1.4 在XHTML中的使用 2.1.5 不推荐 ...
- ubuntu 安装mysql数据库
apt方式安装 官网参考: https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/ 执行命令: sudo wget https://dev.m ...
- 后台实战——用户登录之JWT
https://blog.csdn.net/jackcheng_ht/article/details/52670211
- job无法自动运行基于ABP后台服务 - 后台作业和后台工人
原因: 后台作业和后台工人仅在你的应用程序运行的时候才工作.如果web应用长时间没有被请求执行,Asp.Net应用默认是关闭的 解决方案: 应用程序池(Application Pool),Proces ...