poj2528(线段树)
题目连接:http://poj.org/problem?id=2528
题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报
分析:离散化+线段树,这题因为每个数字其实表示的是一个单位长度,因此离散化后的每个点如果相邻数字间距大于1的话,得在其中加上任意一个数字。
否则 如 [1 10] [1 3] [5 10]这组数据能看见3种海报,而离散化后[1,3,5,10]对应[1,2,3,4],更新[1,2]再更新[3,4]就能看见两种海报了。所以离散化应为[1,2,3,4,5,9,10].
#pragma comment(linker,"/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define N 200010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
bool has[N];
int le[N],ri[N];
int col[N<<],X[N];
int ans;
int bin(int key,int n,int a[])
{
int l=,r=n-;
while(l<=r)
{
int m=(l+r)>>;
if(a[m]==key)return m;
if(a[m]<key)l=m+;
else r=m-;
}
}
void Pushdown(int rt)
{
if(col[rt]!=-)
{
col[rt<<]=col[rt<<|]=col[rt];
col[rt]=-;
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt]=c;
return;
}
Pushdown(rt);
int m=(l+r)>>;
if(L<=m)update(L,R,c,lson);
if(m<R)update(L,R,c,rson);
}
void query(int l,int r,int rt)
{
if(l==r)
{
if(col[rt]!=-)
{
if(!has[col[rt]])ans++;
has[col[rt]]=true;
}
return;
}
Pushdown(rt);
int m=(l+r)>>;
query(lson);
query(rson);
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int nn=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&le[i],&ri[i]);
X[nn++]=le[i];
X[nn++]=ri[i];
}
sort(X,X+nn);
int m=;
for(int i=;i<nn;i++)
if(X[i]!=X[i-])X[m++]=X[i];
for(int i=m-;i>;i--)
if(X[i]!=X[i-]+)X[m++]=X[i-]+;
sort(X,X+m);
FILL(col,-);
for(int i=;i<=n;i++)
{
int l=bin(le[i],m,X);
int r=bin(ri[i],m,X);
update(l+,r+,i,,m,);
}
ans=;FILL(has,false);
query(,m,);
printf("%d\n",ans);
}
}
poj2528(线段树)的更多相关文章
- poj-2528线段树练习
title: poj-2528线段树练习 date: 2018-10-13 13:45:09 tags: acm 刷题 categories: ACM-线段树 概述 这道题坑了我好久啊啊啊啊,,,, ...
- poj2528(线段树+离散化)Mayor's posters
2016-08-15 题意:一面墙,往上面贴海报,后面贴的可以覆盖前面贴的.问最后能看见几种海报. 思路:可以理解成往墙上涂颜色,最后能看见几种颜色(下面就是以涂色来讲的).这面墙长度为1~1000 ...
- POJ2528+线段树
见代码. /* 线段树+Lazy 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度. 现在往墙上贴N张海报,每张海报的宽度是任意的,但是必定是单位宽度的整数倍,且<=1QW. 后贴的海 ...
- POJ2528 线段树的区间操作
首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...
- poj2528 线段树+离散化 (倒序)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- poj2528线段树解题报告,离散化+线段树
题目网址:http://poj.org/problem?id=2528 题意: n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=1 ...
- poj2528(线段树区间替换&离散化)
题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行 n 表接下来有 n 行形如 l, r 的输入, 表在区 ...
- POJ2528线段树基础
開始就直接用延迟标记搞了下.最后发现内存肯定会爆了.数据太大了. 问了瓜神,原来应该用离散化来做这题,详细见凝视 #include <cstdio> #include <cstrin ...
- POJ2528线段树段更新逆序异或(广告牌)
题意: 可以这样理解,有一条直线,然后用n条线段去覆盖,最后问全部都覆盖完之后还有多少是没有被完全覆盖的. 思路: 一开始想的有点偏,想到起点排序,然后..失败了,原因是忘记了题目 ...
- poj2528 线段树+离散化
由于坐标可能很大,此时需要离散化,将值转化为对应的坐标. #include<stdio.h> #include<algorithm> using namespace std; ...
随机推荐
- 全方位深度剖析--性能测试之LoardRunner 介绍
一.介绍 LoardRunner是一种预测系统行为和性能负载的测试工具.通过模拟上千万用户实施并发负载及实时性能监控的方式来确认和查找系统的瓶颈,LoardRunner能够对整个企业架构进行测试.通过 ...
- 浅C#中的装箱和拆箱
1.什么是装箱和拆箱? 简单的来说: 装箱就是值类型转换为引用类型:拆箱就是引用类型转换为值类型 值类型,包括原类型(Sbyte.Byte.Short.Ushort.Int.Uint.Long.Ulo ...
- Friends
Description Mike has many friends. Here are nine of them: Alice, Bob, Carol, Dave, Eve, Frank, Glori ...
- response.sendRedirect 传递参数的问题
response.sendRedirect是通过浏览器来做转向的. 假设在A.jsp页面设置request.setAttribute("username","admin& ...
- How to find configuration file MySQL uses?(转)
http://www.dbasquare.com/2012/04/01/how-to-find-mysql-configuration-file/ A customer called me today ...
- box-sizing:content-box
box-sizing:content-box 规定两个并排的带边框的框:
- Spring2.5学习3.3_@Autowire注解实现手动装配
@Autowired默认按类型装配,假设我在personDao 字段上加了@Autowired注解,那么就会默认取personDao 字段的类型在Spring容器中寻找与这个类型匹配的bean,寻找到 ...
- Android手机便携式wifi的使用及无线数据传输(主要针对XP系统)
适用条件: 1.可以上网的安卓系统2.2以上的智能手机,或有便携式wifi功能的安卓智能手机 2.有无线网卡的笔记本电脑或台式机(特别是XP系统) 测试手机:中兴U930 电脑:华硕K50系列笔记本 ...
- 与众不同 windows phone (3) - Application Bar(应用程序栏)
原文:与众不同 windows phone (3) - Application Bar(应用程序栏) [索引页][源码下载] 与众不同 windows phone (3) - Application ...
- Ubuntu12.04创建 Eclipse launcher
Ubuntu 12.04 默认无法launcher Eclipse快捷图标到左侧Dash,需要手工配置,步骤如下: 1) 首先,创建并打开 ~/.local/share/applications/op ...