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张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- URLSearchParams 接口定义处理 URL 参数串
基本使用方法如下 /* * URLSearchParams属性 * @语法:new URLSearchParams(parameter); */ (function(){ var str = &quo ...
- oracle如何四舍五入?
转自:http://www.jb51.net/article/84924.htm 取整(向下取整): 复制代码代码如下: select floor(5.534) from dual;select tr ...
- 微信小程序 --- 完成小程序支付功能
最近开发小程序,一直在看小程序的支付.经过一天的努力,小程序支付功能最终实现了. 下面感谢 csdn 博主:千堆雪惹尘埃 发布的 " 小程序与php 实现微信支付 " 原文地址: ...
- Servlet------>request和response控制编码乱码问题
我在request篇和response都有提到,觉得会忘记,所以从新整理一下 request细节四----->通过request控制编码问题 第一种方式是通过设置------>reques ...
- network command assistant
这篇文章收集了久经考验靠谱的命令,也收集了几个比较新的命令.多数命令都可以在图形桌面执行,即使是没什么终端使用经验的Linux用户也会常常执行命令来使用ping或是其它的网络诊断工具. 1.curl ...
- CRM - 销售与客户
一.销售与客户 - 表结构 ---公共客户(公共资源) 1.没有报名 2.3天没有跟进 3.15天没有成单 客户分布表 龙泰 男 yuan 2018-5-1 3天未跟进 龙泰 男 三江 2018-5- ...
- CentOS 6.4下Squid代理服务器的安装与配置(转)
add by zhj: 其实我们主要还是关注它在服务器端使用时,充当反向代理和静态数据缓存.至于普通代理和透明代理,其实相当于客户端做的事,和服务端没有什么关系.另外,Squid的缓存主要是缓存在硬盘 ...
- Mirror--使用证书配置镜像模板
--==================================================================--该文档主要用于内部配置模板--场景:--主服务器:192.1 ...
- python基础之员工信息表作业
周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tea ...
- Flask系列之蓝图中使用动态URL前缀
让我们先来看一个简单的例子,假设有下面这样一个蓝图(是关于用户主页的): from flask import Blueprint, render_template profile = Blueprin ...