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; ...
随机推荐
- WebResponse 取出全国省市区的邮编
WebResponse用法(根据省市区地址查询其邮编): class Program { static string url { get; set; } static void Main(string ...
- NOIP201101&&05
NOIP200701奖学金 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 某小学最近得到了一笔赞助 ...
- 《APUE》第五章笔记
第五章具体介绍了标准I/O库的各种细节,要是一一列出来,有费精力且可能列不全,故只讲平常多用到的.标准输入输出是由一大批函数组成的. 要记住,标准输入输出是有缓冲的,就是当缓冲区的数据满了的时候,才会 ...
- javascript之数据推送
我们使用ajax与后台服务进行交互,常常是通过触发事件来单次交互,但对于有些web应用来说,需要前台与后台保持长连接,前端不定时地接收后台推送的数据信息, 例如:股票行情分析.聊天室和网页在线游戏等. ...
- ASP.Net MVC中JSON处理。
实体数据Model [Serializable] public class UserModel { //public UserModel(string name, string classname, ...
- AngularJS(7)-表格
ng-repeat 指令可以完美的显示表格. <!DOCTYPE html> <html lang="en"> <head> <meta ...
- 利用Google GCM发送push通知到Android客户端
// 这个可以需要在google账号中申请,勾选gcm服务选项 $apiKey = 'AIzaSyC6h3ysrn2HDCBqONTo2vKIVVuktIFoxxx'; $headers = arra ...
- linux命令 chattr超级权限控件
linux命令:chattr 1.作用 修改ext2和ext3文件系统属性(attribute),使用权限超级用户. linux命令:chattr 1.作用修改ext2和ext3文件系统属性(at ...
- Delphi摄像头操作
/*Title:Delphi摄像头操作 *Author:Insun *Blog:http://yxmhero1989.blog.163.com *From:www.4safer.com */ 为了笔耕 ...
- XE5 ANDROID平台 调用 webservice
服务端需要midas.dll XE5对android的平台支持很有吸引力,虽然目前用来直接开发应用到安卓市场卖赚钱可能性估计不大(安卓市场目前国内好像都是免费的天下),但是对于企业应用很是很有帮助 ...