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; ...
随机推荐
- Swift属性
属性的存储 属性的主要作用是存储数据,可以常量属性和变量属 性: struct FixedLengthRange { var firstValue: Int let length: Int } var ...
- HTML+CSS学习笔记(5)- 与浏览者交互,表单标签
HTML+CSS学习笔记(5)- 与浏览者交互,表单标签 1.使用表单标签,与用户交互 网站怎样与用户进行交互?答案是使用HTML表单(form).表单是可以把浏览者输入的数据传送到服务器端,这样服务 ...
- (转)Mongodb相对于关系型数据库的优缺点
与关系型数据库相比,MongoDB的优点:①弱一致性(最终一致),更能保证用户的访问速度:举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的精确值 ...
- (转)Ehcache作为分布式缓存的研究
ehcache支持两种拓扑结构,一种是Distributed Caching,另一种是Replicated Caching Distributed Caching 这和一般意义上的分布式缓存非常类似, ...
- 洛谷 P1890 gcd区间
P1890 gcd区间 题目提供者 洛谷OnlineJudge 标签 数论(数学相关) 难度 普及/提高- 题目描述 给定一行n个正整数a[1]..a[n]. m次询问,每次询问给定一个区间[L,R] ...
- java web中cookie的永久创建与撤销
一.首先是创建cookie 当在数据库中查找知道所输入的用户名和密码正确之后,就开始创建: String cb=request.getParameter("cb");//cb就是登 ...
- iOS进阶——可取消的block
+ (id)performBlock:(void (^)())aBlock onQueue:(dispatch_queue_t)queue afterDelay:(NSTimeInterval)del ...
- httpc服务器错误类型大全
HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败HTTP 401.2 - 未授权:服务器配置问题导致登录失败HTTP 401.3 - ACL 禁止访问资源HTTP 401.4 ...
- struts2使用struts2-bootstrap-plugin插件
1.下载插件 http://code.google.com/p/struts2-bootstrap/ 2.添加maven依赖 <dependency> <groupId>com ...
- Google的小秘密
google有计算器的功能,例如在google中搜索25*25.lg(13)等,看会出现什么样的结果. http://www.google.com/microsoft 微软风格的入口 http: ...