POJ 2528 Mayor's posters(线段树染色问题+离散化)
http://poj.org/problem?id=2528
题意:
给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报。
题意:
这道题目就相当于对x轴染色,然后计算出最后还能看见多少种颜色。
由于数据量是给定的,所以需要进行离散化。但是这道题目的话,不能简单的离散化,前后相差大于1的话需要额外的插一个数。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; int n;
int ans;
int col[maxn<<];
int vis[maxn<<];
int l_pos[maxn<<],r_pos[maxn<<];
int x[maxn<<]; void PushDown(int o)
{
if(col[o]!=-)
{
col[o<<]=col[o<<|]=col[o];
col[o]=-;
}
} void update(int L, int R, int l, int r, int ID, int o)
{
if(L<=l && R>=r)
{
col[o]=ID;
return;
}
PushDown(o);
int mid=(l+r)/;
if(L<=mid) update(L,R,l,mid,ID,o<<);
if(R>mid) update(L,R,mid+,r,ID,o<<|);
} void query(int L, int R, int l, int r, int o)
{
if(col[o]!=-)
{
if(vis[col[o]]==) //每种颜色统计一次
{
ans++;
vis[col[o]]=;
}
col[o]=-;
return;
}
if(l==r) return;
PushDown(o);
int mid=(l+r)/;
if(L<=mid) query(L,R,l,mid,o<<);
if(R>mid) query(L,R,mid+,r,o<<|);
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
memset(col,-,sizeof(col));
memset(vis,,sizeof(vis)); scanf("%d",&n);
int cnt=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&l_pos[i],&r_pos[i]);
x[++cnt]=l_pos[i];
x[++cnt]=r_pos[i];
} sort(x+,x+cnt+);
int cntt=cnt;
for(int i=;i<=cntt;i++)
{
if(x[i]-x[i-]>) x[++cnt]=x[i-]+; //插点
}
//离散化
sort(x+,x+cnt+);
int num=unique(x+,x+cnt+)-(x+);
for(int i=;i<=n;i++)
{
l_pos[i]=lower_bound(x+,x+num+,l_pos[i])-(x+);
r_pos[i]=lower_bound(x+,x+num+,r_pos[i])-(x+);
update(l_pos[i],r_pos[i],,num,i,);
} ans=;
query(,num,,num,);
printf("%d\n",ans);
}
return ;
}
POJ 2528 Mayor's posters(线段树染色问题+离散化)的更多相关文章
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ 2528 Mayor’s posters (线段树段替换 && 离散化)
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- 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 (线段树)
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...
- poj 2528 Mayor's posters(线段树)
题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- Portal是用来干什么的?
portal是指一个门户网站 例如sina就采用了Portal技术 他是.net的一个开源的网站模版什么是Portal?英文字面是“入口”,国内有叫“门户”技术的,但我觉得“集成”技术更能表达它的意思 ...
- 【BZOJ3518】点组计数 欧拉函数
[BZOJ3518]点组计数 Description 平面上摆放着一个n*m的点阵(下图所示是一个3*4的点阵).Curimit想知道有多少三点组(a,b,c)满足以a,b,c三点共线.这里a,b,c ...
- 【BZOJ4523】[Cqoi2016]路由表 Trie树模拟
[BZOJ4523][Cqoi2016]路由表 Description 路由表查找是路由器在转发IP报文时的重要环节.通常路由表中的表项由目的地址.掩码.下一跳(Next Hop)地址和其他辅助信息组 ...
- Win10安装软件时出现2502、2503错误代码的问题
主要是权限不够,C:\Windows\temp先访问权限 找到该目录,选择temp文件夹,右键弹出快捷菜单,选择“管理员取得所有权”.确定,OK. 再安装软件OK.
- 170807、intellij idea maven集成lombok实例
简介: lombok 通过简单注解方式简化java代码.(如消除实体对象的get/setter方法.日志对象声明等...) 安装步骤: 1.选择支持注解处理:Settings-->Build-- ...
- 使用Yii2中dropdownlist实现地区三级联动的例子
原文:http://www.yiichina.com/code/636 <?php use yii\helpers\Url; use yii\widgets\ActiveForm; use yi ...
- 利用Dockerfile构建一个基于CentOS 7镜像
利用Dockerfile构建一个基于CentOS 7,包括java 8, tomcat 7,php ,mysql+mycat的镜像. Dockerfile内容如下: FROM centosMAINTA ...
- CVP沙龙
关于职场: 35岁之后,还去招聘网站投简历? 35岁可能是个分水岭 95后比一些80后还强, 有些80后玻璃心 35岁有的可能已经是VP了 应该深入积累而不是蜻蜓点水 只有第一年成长了,之后是重复劳动 ...
- android 导出数据库文件
1.打开dos窗口,进入自己SDK路径下,再进入platform-tools下边 2.进入shell模式: adb shell 3.获取所有root权限: su root 4.打开需要导出的数据库文件 ...
- format的用法:python
https://www.cnblogs.com/wongbingming/p/6848701.html 它通过{}和:来代替%.通过位置 In [1]: '{0},{1}'.format('kzc', ...