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

#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. 《TCP/IP详解 卷一》读书笔记-----动态路由协议

    1.以下条件只要有一个不满足,则需要使用动态路由协议:1)网络规模小,2)只有一个连接点用于连接其他网络,3)没有冗余的路由器(一般用作备份) 2.所谓动态路由就是各个路由器与自己相邻的路由器交换各自 ...

  2. selenium循环点击文本框

    1.可以用xpath循环点击checkbox List<WebElement> list = dr.findElements(By.className("datagrid-row ...

  3. 离散化+线段树 POJ 3277 City Horizon

    POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...

  4. sql 入门经典(第五版) Ryan Stephens 学习笔记  第四部分:建立复杂的数据库查询/

    第十三章: 在查询表里结合表 1.等值结合 : // 选择 tabla_a 和table_b 中id相等的行,输出 他们的id 和name select table_a.id , table_a.na ...

  5. parse_url等函数

    $_SERVER["REQUEST_URI"]://这个可以获取域名后的url,比如/test1/parse_url.php?id=7&name=wuhan 常见用法$ur ...

  6. High Performance Animations

    http://www.html5rocks.com/zh/tutorials/speed/high-performance-animations/

  7. WorldWind源码剖析系列:BMNG类构造函数深入分析

    BMNG构造函数深入分析 一.主要类图 二.主要功能: 1)        BMNG类 BMNG类将包含以“Blue Marble”为主题的所有可渲染影像的根节点添加到当前星球的可渲染对象列表中,包括 ...

  8. JNI 程序开发

    参考资料: http://blog.csdn.net/wwj_748/article/details/28136061 JNI_最简单的Java调用C/C++代码 http://blog.csdn.n ...

  9. SQLServer 语句-创建索引

    语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100GO /*实例*/USE 库名GOIF EXISTS (SELECT * ...

  10. 用virtualenv管理python3运行环境

    1. 简介 virtualenv可以用来管理互不干扰的独立python虚拟环境,在有些场景下非常有用,例如: 你有两个python项目,一个是python2.7的,另一个是python3的,可以创建两 ...