poj2528 线段树+离散化
由于坐标可能很大,此时需要离散化,将值转化为对应的坐标。
#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 线段树+离散化的更多相关文章
- poj2528(线段树+离散化)Mayor's posters
2016-08-15 题意:一面墙,往上面贴海报,后面贴的可以覆盖前面贴的.问最后能看见几种海报. 思路:可以理解成往墙上涂颜色,最后能看见几种颜色(下面就是以涂色来讲的).这面墙长度为1~1000 ...
- poj2528 线段树+离散化 (倒序)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- POJ2528 线段树离散化
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 62771 Accepted: 18120 ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- poj-2528线段树练习
title: poj-2528线段树练习 date: 2018-10-13 13:45:09 tags: acm 刷题 categories: ACM-线段树 概述 这道题坑了我好久啊啊啊啊,,,, ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- [UESTC1059]秋实大哥与小朋友(线段树, 离散化)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
随机推荐
- Ajax类库需要注意的问题
构建Ajax类库时,注意四步就可以了: 1:创建Ajax 对象 2:链接服务器 3:发送请求 4:返回响应 下面是我自己写的一个Ajax类库: function ajax(url,fnn,fai) ...
- 什么是multipart/form-data请求
根据http/1.1 rfc 2616的协议规定,我们的请求方式只有OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE等,那为为何我们还会有multipart/form-da ...
- scanf和cin的差异
scanf和cin的差异 引例:http://www.cnblogs.com/shenben/p/5516996.html 大家都知道,在C++中有两种输入.输出方式—scanf和cin,但是,它们之 ...
- 24Mybatis_延迟加载——用association来实现
resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能. 需求: 如果查询订单并且关 ...
- 【转】【SEE】基于SSE指令集的程序设计简介
SSE技术简介 Intel公司的单指令多数据流式扩展(SSE,Streaming SIMD Extensions)技术能够有效增强CPU浮点运算的能力.Visual Studio .NET 2003提 ...
- [IPSEC PKI]
PKI: 对称加密 非对称加密(混合加密) 数字签名 理论概述: (1)预备知识 对称加密:加密密钥和揭秘蜜钥是同一个密钥 缺点:不适合在互联网上传输密钥 密钥维护工作量大 n(n-1)/2 : ...
- log_bin_trust_function_creators变量解释
在MySQL主从复制机器的master的数据库中创建function,报出如下错误: Error Code: 1418. This function has none of DETERMINISTIC ...
- [iOS翻译]Cocoa编码规范
简介: 本文整理自Apple文档<Coding Guidelines for Cocoa>.这份文档原意是给Cocoa框架.插件及公共API开发者提供一些编码指导,实质上相当于Ap ...
- [CareerCup] 11.7 Tower of People in Circus 马戏团的人塔
11.7 A circus is designing a tower routine consisting of people standing atop one another's shoulder ...
- LeetCode 笔记27 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...