见代码。

 /*
线段树+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+线段树的更多相关文章

  1. poj-2528线段树练习

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

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

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

  3. POJ2528 线段树的区间操作

    首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...

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

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

  5. poj2528线段树解题报告,离散化+线段树

    题目网址:http://poj.org/problem?id=2528 题意: n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=1 ...

  6. poj2528(线段树区间替换&离散化)

    题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行  n 表接下来有 n 行形如 l, r 的输入, 表在区 ...

  7. POJ2528线段树基础

    開始就直接用延迟标记搞了下.最后发现内存肯定会爆了.数据太大了. 问了瓜神,原来应该用离散化来做这题,详细见凝视 #include <cstdio> #include <cstrin ...

  8. POJ2528线段树段更新逆序异或(广告牌)

    题意:      可以这样理解,有一条直线,然后用n条线段去覆盖,最后问全部都覆盖完之后还有多少是没有被完全覆盖的. 思路:      一开始想的有点偏,想到起点排序,然后..失败了,原因是忘记了题目 ...

  9. poj2528 线段树+离散化

    由于坐标可能很大,此时需要离散化,将值转化为对应的坐标. #include<stdio.h> #include<algorithm> using namespace std; ...

随机推荐

  1. 交叉编译lsof for android

    Android 自带的那个 lsof 实际上是 toolbox 里的,功能十分单一,除了显示出所有进程的所有打开的文件外就什么都不能做,连说明也没有 :-( 于是为了 htop 用着爽一点,还是自己编 ...

  2. Cocos2d-x中背景音乐播放暂停与继续

    背景音乐播放暂停与继续似乎我们很少使用,事实上也正是如此,背景音乐播放暂停与继续实例代码如下: SimpleAudioEngine::getInstance()->pauseBackground ...

  3. NodeJS V8 GC概览

    [A tour of V8: Garbage Collection] http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection 基本是 ...

  4. Php 魔术常量

    魔术常量 由于其值在程序运行过程中不允许更改,所以是常量:其值,又是运行环境不同而不现,所以叫魔术. __DIR__            当前脚本文件的路径 示例: __LINE__         ...

  5. CSS的浮动和清除

    CSS浮动和清除 什么是浮动? 在实现效果上,让元素浮起来(飘起来),动起来(向左或向右移动) 浮动本质:就是将两个块元素同存一行. float 取值:主要是对浮动的方向进行控制 left:让元素向左 ...

  6. CodeBlocks对C++模板的支持

    坦率的说CodeBlocks是一款不错的跨平台编译器,一般编写C/C++都是使用它,但最近在编写C++模板文件时,发现它对模板的支持并不是很好.具体表现在模板的定义与声明分开的问题上. 一般编写C/C ...

  7. Linux 信号量 生产者消费者小例题

    菜鸟偶遇信号量,擦出火花(只有不熟才会有火花).于是上网搜资料和看<Unix环境高级编程>实现了几个小例题,高手请勿喷!这几位写得非常好啊: 题目来源: http://www.it165. ...

  8. 【转】VS2012发布网站详细步骤

    1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击<新建..>,创建新的发布配置文件: 输入你自 ...

  9. java集合的互转

    List<-->数组.List<-->Set.数组<-->Set.Map将键转化为Set.Map将值转化为Set.Map将值转化为List等集合常 public c ...

  10. C#让TopMost窗体弹出并置顶层但不获取当前输入焦点的终极办法

    为了使程序在弹出窗口时置顶层且不获取系统输入焦点,避免影响用户当前的操作,来电通来电弹屏软件尝试过N多种办法,例如:弹出前保存当前焦点窗口句柄,弹出时因为使用TopMost系统默认将焦点交给了弹出窗口 ...