POJ2528+线段树
见代码。
/*
线段树+Lazy
题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。
现在往墙上贴N张海报,每张海报的宽度是任意的,但是必定是单位宽度的整数倍,且<=1QW。
后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖先贴的海报。
现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报?
(PS:看见一部分也算看到。)
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; struct Node{
int L,R,color;
}tree[ maxn<< ];
struct NODE{
int L,R;
bool operator<(const NODE &tmp ) const{
return R<tmp.R;
}
}a[ maxn ];
int myhash[ maxn ];
int ANS;
int vis[ maxn ]; int lisanhua( int k ){
sort( myhash,myhash+k );
int cnt = unique( myhash,myhash+k ) - myhash;
return cnt;
} void build( int L,int R,int n ){
if( L==R ){
tree[ n ].L = L;
tree[ n ].R = R;
tree[ n ].color = ;
return ;
}
tree[ n ].L = L;
tree[ n ].R = R;
tree[ n ].color = ;
int mid = (L+R)/;
build( L,mid,L(n) );
build( mid+,R,R(n) );
} void PushDown( int n,int new_color ){
if( tree[ n ].color!=&&tree[ n ].color!=new_color ){
tree[ L(n) ].color = tree[ R(n) ].color = tree[ n ].color;
tree[ n ].color = ;
}
} void update( int x,int y,int new_color,int L,int R,int n ){
if( x==L&&y==R ){
tree[ n ].color = new_color;
return ;
}
PushDown( n,new_color );
int mid = (L+R)/;
if( mid>=y ) update( x,y,new_color,L,mid,L(n) );
else if( mid<x ) update( x,y,new_color,mid+,R,R(n) );
else {
update( x,mid,new_color,L,mid,L(n) );
update( mid+,y,new_color,mid+,R,R(n) );
}
} void query( int n ){
if( tree[n].color ){
if( vis[tree[n].color]== ){
vis[tree[n].color] = ;
ANS++;
}
return ;
}
//int mid = (tree[n].L+tree[n].R)/2;
query( L(n) );
query( R(n) );
} int main(){
int T;
scanf("%d",&T);
while( T-- ){
int n;
scanf("%d",&n);
int k = ;
for( int i=;i<=n;i++ ){
scanf("%d%d",&a[i].L,&a[i].R);
myhash[ k++ ] = a[i].L;
myhash[ k++ ] = a[i].R;
}
int cnt = lisanhua( k );
build( ,cnt, );
//printf("build\n");
for( int i=;i<=n;i++ ){
int x = lower_bound( myhash,myhash+cnt,a[i].L )-myhash;
int y = lower_bound( myhash,myhash+cnt,a[i].R )-myhash;
x++,y++;
//printf("i = %d\n",i);
//printf("x = %d, y=%d\n",x,y);
update( x,y,i,,cnt, );
}
ANS = ;
memset( vis,,sizeof( vis ) );
//printf("query\n");
query( );
printf("%d\n",ANS);
}
return ;
}
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 线段树的区间操作
首先应该对该[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; ...
随机推荐
- Eclipse Code Templates设置
从工作开始,经历了几个项目的开发,现在的项目一般都是一个团队共同开发,而每个人都有自己的编码习惯,为了统一格式,项目组在项目开发之前都会制定一系列的规范.俗话说约定优于配置,但是在执行过程中往往发现效 ...
- 双网卡route配置
目前仅适用于windows: 192.168.*.*网段适用于上外网的 10网段适用于内网 route add 10.0.0.0 mask 255.0.0.0 10.34.6.1route add 1 ...
- sqlserver 大文件脚本执行
sqlserver2008中需要执行大文件的脚本,查询分析器中打不开,需要用到sql命令,开始使用osql命令,不过提示对应sqlserver2008中的驱动找不到(具体原因未分析-空闲时在处理),使 ...
- Mysql 的安装与配置
MySQL的安装 第1步:下载 第2 步:以管理员身份进行安装 第3步:选择安装类型. 第4步:设置MySQL安装目录,及数据库文件目录 第5步:安装结束,开启配置向导 第6步:选择配置类型 第7步: ...
- L009-oldboy-mysql-dba-lesson09
L009-oldboy-mysql-dba-lesson09 mysql> grant replication salve,replication client on *.* to ‘repl_ ...
- sphinx 占用大量内存
http://www.coreseek.com/forum/2_1847_0.html(转) 刚开始没改下面2句时,内存占用比较多,在生成index的时候就占用了! 下面是解决方法: 每个索引中写上 ...
- CSS3 弹性盒布局模型(转)
简介 引入弹性盒布局模型的目的是提供一种更加有效的方式来对一个容器中的条目进行排列. 对齐和分配空白空间.即便容器中条目的尺寸未知或是动态变化的,弹性盒布局模型也能正常的工作.在该布局模型中,容器会根 ...
- C#定时器
在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类里 3.定义在System.Timers.Timer类里 S ...
- mongodb 级联操作查询时,关联条件
ObjectId id=new ObjectId("123"); c=c.where("relation_type.$id").is(id);
- GridView分页排序
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewPage.asp ...