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张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树
[BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...
- c# comboBox与数据库中的数据绑定
private void comBoxBinding() { SqlConnection connection = this.getConnection(); connection.Open(); S ...
- 解决Activity启动黑屏及设置android:windowIsTranslucent不兼容activity切换动画问题
From:http://blog.csdn.net/fancylovejava/article/details/39643449 之前在做 APP 的时候不太关注这个问题,因为自己在使用其他 APP ...
- django后台导入excel文件
1.django 如何从后台上传excel中批量解析数据 要从django后台导入的excel中批量解析数据,举一个例子,我们向后抬批量导入svn历史数据数据格式 假设excel表中有4列,每列分别是 ...
- 华硕蓝光刻录机在MAC系统里能用吗?
答案是刻录功能不能用(没有驱动),但可以当外置光驱用.需要注意的是单单把刻录机插到MAC电脑上是没有反应的,放入光盘后Finder里会出现一个可移动设备.
- Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录
刚刚入手Yii2高级模板不久,部署项目时,得部署2个应用,个人感觉很繁琐,就将前后台入口文件全部拿到项目根目录.但是一看,完了,出错了!找教程找不到,还是自己解决吧 为了以后好升级,不改变Yii2核心 ...
- 使用异步消息处理更新UI线程
1. Android的UI时线程不安全的,如果在子线程中更新UI会出现异常,导致程序崩溃. 为了解决如上这些问题,我们常用的做法就是使用Android的异步消息机制实现即可(创建一个Message对象 ...
- Linux系统stat指令用法
stat指令:文件/文件系统的详细信息显示. stat命令主要用于显示文件或文件系统的详细信息,该命令的语法格式如下: stat命令-->用来显示文件的详细信息,包括inode, atime, ...
- This module embeds Lua, via LuaJIT 2.0/2.1, into Nginx and by leveraging Nginx's subrequests, allows the integration of the powerful Lua threads (Lua coroutines) into the Nginx event model.
openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers https://github.com/openre ...
- installEventFilter可以安装到任何QObject的子类,并不仅仅是UI组件。事件过滤器和安装过滤器的组件必须在同一线程,在它们分属在不同线程时,事件过滤器也是不起作用的
Qt的事件知识点: ①事件对象创建完毕后,Qt 将这个事件对象传递给 QObject 的 event() 函数.event() 函数并不直接处理事件,而是将这些事件对象按照它们不同的类型,分发给不同的 ...