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张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- 【Android】TextView动态设置android:drawableLeft|Right|Top|Bottom,SetColor
Android中有时需动态设置控件四周的drawble图片,这个时候就需要调用 setCompoundDrawables(left, top, right, bottom),四个参数类型都是drawa ...
- mysql日期处在某两个时间段之间的between比较
where SYSDATE() between '2018-08-28 09:21:48' and '2018-08-28 09:25:48' sysdate()等于2018-08-28 09:23: ...
- 【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)
标签: 1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be c ...
- angular -- get请求该如何使用?
在做 angualr 的开发过程中,经常会用到的就是 ajax 请求.下面是 get 请求示例: 如果存在多个 get 请求可以考虑进行封装下: // get 携参数访问 ajaxGet(getUrl ...
- 问答项目---登陆也要做验证!(JS和PHP验证)
简单JS示例: var login = $( 'form[name=login]' ); login.submit( function () { if (validate.loginAccount & ...
- 三维凸包求凸包表面的个数(HDU3662)
3D Convex Hull Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- html lang="zh-cn"解决Mac版Firefox中文字体显示问题
这两天在Mac下被Firefox的中文字体显示问题所困扰.在Firefox中将Sans-serif字体设置为SimSun-ExtB(新宋体)或英文字体(这时会用Mac默认中文字体),如下图: 浏览园子 ...
- Android中的Apk的加固(加壳)原理解析和实现(转)
一.前言 今天又到周末了,憋了好久又要出博客了,今天来介绍一下Android中的如何对Apk进行加固的原理.现阶段.我们知道Android中的反编译工作越来越让人操作熟练,我们辛苦的开发出一个apk, ...
- nginx lua模块安装
1.安装LuaJIT,LuaJIT为LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language wget http ...
- 在一台server上部署多个Tomcat
版权声明: https://blog.csdn.net/u011518709/article/details/27181665 在一台server上配置多个Tomcat的方法: 这几天因为在研究OGS ...