由于坐标可能很大,此时需要离散化,将值转化为对应的坐标。

#include<stdio.h>
#include<algorithm>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 200010
int mark[maxn*],sum[maxn*],ans;
struct Node
{
int x;
int y;
}node[maxn];
int num[maxn*];
void pushup(int rt)
{
if(sum[rt<<]&&sum[rt<<|])
sum[rt]=;
else sum[rt]=;
}
void build(int l,int r,int rt)
{ if(l==r)
{
sum[rt]=;
return ;
}
int m=(l+r)/;
build(lson);
build(rson);
pushup(rt);
} void updata(int L,int R,int l,int r,int rt,int c)
{
if(sum[rt]) return ;
if(l>=L&&R>=r)
{
sum[rt]=;
if(!mark[c])
{
mark[c]=;
ans++;
return ;
}
return ;
}
int m=(l+r)/;
if(m>=L)
updata(L,R,lson,c);
if(R>m)
updata(L,R,rson,c);
pushup(rt);
}
int find(int val,int x,int y)
{
int l=x;
int r=y;
int m;
while(l<=r)
{
m=(l+r)/;
if(num[m]==val)
return m;
else if(num[m]>val)
r=m-;
else l=m+;
}
return -;
}
int main()
{
int i,t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int m=;
for(i=;i<n;i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
num[m++]=node[i].x;
num[m++]=node[i].y;
}
sort(num+,num+m);
int k=;
//去重复
for(i=;i<m;i++)
{
if(num[i]!=num[i-])
num[k++]=num[i];
}
//防止相邻的出现问题
for(i=k-;i>;i--)
{
if(num[i]!=num[i-]+)
num[k++]=num[i-]+;
}
memset(mark,,sizeof(mark));
sort(num+,num+k);
build(,k-,);
ans=;
for(i=n-;i>=;i--)//倒着贴
{
int ll=find(node[i].x,,k-);
int rr=find(node[i].y,,k-);
updata(ll,rr,,k-,,i+);
}
printf("%d\n",ans);
}
}

poj2528 线段树+离散化的更多相关文章

  1. poj2528(线段树+离散化)Mayor's posters

    2016-08-15 题意:一面墙,往上面贴海报,后面贴的可以覆盖前面贴的.问最后能看见几种海报. 思路:可以理解成往墙上涂颜色,最后能看见几种颜色(下面就是以涂色来讲的).这面墙长度为1~1000 ...

  2. poj2528 线段树+离散化 (倒序)

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  3. POJ2528 线段树离散化

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 62771   Accepted: 18120 ...

  4. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  5. poj-2528线段树练习

    title: poj-2528线段树练习 date: 2018-10-13 13:45:09 tags: acm 刷题 categories: ACM-线段树 概述 这道题坑了我好久啊啊啊啊,,,, ...

  6. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  7. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  8. [UESTC1059]秋实大哥与小朋友(线段树, 离散化)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...

  9. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

随机推荐

  1. gym101090 I Painting the natural numbers

    题目地址:http://codeforces.com/gym/101090 题目: The H&H company currently develops AI (artificial inte ...

  2. Unity3D多人协作开发环境搭建

    多人协作 说到多人协作开发,大家都会想到要使用版本控制工具来管理项目,当然最常用的要数SVN和Git了,但是SVN管理Unity3D项目的确有一些不尽人意的地方. 比如:两个人修改了同一个场景,SVN ...

  3. C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字

            /// 去掉字符串中的数字           public static string RemoveNumber(string key)           {            ...

  4. 3016 质子撞击炮 II

    3016 质子撞击炮 II  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description [抱歉数据错误~~已修 ...

  5. 04JavaIO详解_DataInputStream(属于过滤l流)

    DataInputStream这个类是二进制读写的.并且 是过滤流,会一层套一层的.这里就是装饰者模式. public class DataStream1 { public static void m ...

  6. 记2012-2013年一路的Windows Phone历程

    昨天和秦春林同学小聚一次,不厌其烦的唠叨各种认识了许多年的纪念,感觉他仍然保持着那份对技术的追求和梦想,而我却已经变得逐利,每个人享受幸福的方式不一样,因此追逐幸福的过程也就是没有办法一样了,你无法知 ...

  7. salt进程查看插件&salt批量创建用户

    接受key 剔除主机   启动 salt-minion-d     软件包的安装   salt '*' state.sls init.env-init test=true   salt批量创建用户: ...

  8. 关闭linux centos各种声音

    shell报警 #vi /etc/inputrc ================================ set bell-style none 或 echo "set bell- ...

  9. android Camera 中如何修改缩放变焦参数

    如何修改 zoomRatio   修改过程:   1, 先找到 gZoomRatio 数组序列的值   Location: V:\project_code\project_name\ALPS.JB.M ...

  10. Binary Search Tree Iterator

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...