Mayor's posters POJ - 2528 线段树区间覆盖
//线段树区间覆盖
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
int flag;
struct node{
int l,r;
//vis 是这块区域是否完全被覆盖
bool vis;
}tr[N<<];
struct point
{
int id;
int x;
}post[N<<];
int cmp1(point a,point b)
{
return a.x<b.x;
}
int cmp2(point a,point b)
{
if(a.id==b.id)
return a.x<b.x;
return a.id>b.id;
}
void pushup(int u)
{
tr[u].vis=tr[u<<].vis&&tr[u<<|].vis;
}
void build(int u,int l,int r)
{
tr[u]={l,r,};
if(l==r)
return ;
int mid=l+r>>;
build(u<<,l,mid);
build(u<<|,mid+,r);
}
void query(int u,int l,int r)
{
if(tr[u].vis)
return ;
if(tr[u].l==l&&tr[u].r==r)
{
tr[u].vis=;
flag=;
return;
}
int mid=tr[u].l+tr[u].r>>;
if(r<=mid)
query(u<<,l,r);
else if(l>mid)
query(u<<|,l,r);
else
{
query(u<<,l,mid);
query(u<<|,mid+,r);
}
pushup(u);
}
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
//离散化之前的数据
for(int i=;i<*n;i+=)
{
cin>>post[i].x>>post[i+].x;
post[i].id=post[i+].id=i;
}
//按照离散化之前的数据排序
sort(post,post+*n,cmp1);
//离散化
int tot=,pre=;
for(int i=;i<*n;i++)
{
//如果和上一个一样
//那么排名也就一样
if(post[i].x==pre)
{
post[i].x=tot;
}
//如果不一样,记录当前值
//排名++
else
{
pre=post[i].x;
post[i].x=++tot;
}
}
build(,,*n);
//排序,从后往前贴
//id大的在前
sort(post,post+*n,cmp2);
int ans=;
for(int i=;i<*n;i+=)
{
int l=post[i].x;
int r=post[i+].x;
flag=;
query(,l,r);
if(flag)
ans++;
}
cout<<ans<<endl;
}
return ;
}
Mayor's posters POJ - 2528 线段树区间覆盖的更多相关文章
- Mayor's posters POJ - 2528(线段树 + 离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74745 Accepted: 21574 ...
- Mayor's posters POJ - 2528 线段树(离散化处理大数?)
题意:输入t组数据,输入n代表有n块广告牌,按照顺序贴上去,输入左边和右边到达的地方,问贴完以后还有多少块广告牌可以看到(因为有的被完全覆盖了). 思路:很明显就是线段树更改区间,不过这个区间的跨度有 ...
- poj 2528 线段树区间修改+离散化
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...
- POJ 2528 Mayor's posters 贴海报 线段树 区间更新
注意离散化!!!线段树的叶子结点代表的是一段!!! 给出下面两个简单的例子应该能体现普通离散化的缺陷: 1-10 1-4 5-10 1-10 1-4 6-10 普通离散化算出来的结果都会是2,但是第二 ...
- POJ - 2528Mayor's posters (离散化+线段树区间覆盖)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- POJ - 2528 Mayor's posters (离散化+线段树区间修改)
https://cn.vjudge.net/problem/POJ-2528 题意 给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张? 分析 ...
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】
Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
随机推荐
- 如何播放 WAV 文件?
from http://www.vckbase.com/index.php/wv/434 平时,你在多媒体软件的设计中是怎样处理声音文件的呢?使用Windows 提供的API函数 sndPlaySou ...
- C语言学习笔记--void
void真正发挥的作用在于: (1) 对函数返回的限定: (2) 对函数参数的限定. 先给一个例子 定义函数返回值 函数名(参数1,参数2,参数3,.......){内容}int sum(int a ...
- Luogu P1280 尼可的任务(dp)
题意: 时间为n,有k个任务,每个任务有一个开始时间和持续时间,从第一分钟开始,如果有开始的任务就要做,问最大空闲时间 n,k<=1e5 思路: 设 dp[i]为i~n时间中最大空闲时间,vec ...
- Flink与HanLP集成使用
自然语言处理是机器学习的一个重要分支,在智能翻译.智能问答.舆情监控.ChatOps等都有很好的应用场景,目前比较好的一个开源实现工具是何晗大神的HanLP,主页(http://hanlp.com/) ...
- WARNING OGG-00706 Failed to add supplemental log group on table
在配置OGG时,需要给同步的表添加补充日志,在ggsci命令行执行 add trandata user.table SQL> desc jack.t1 Name Null? Type --- ...
- num10---适配器模式
1.类适配器 Adapter类,通过继承 被适配的类,实现目标类的接口,完成适配. 分析: java 单继承,所以适配器类 需要继承 被适配类,这就要求目标类必须是接口,有一定局限性. 被适配类的方法 ...
- 【C++】随机数引擎
rand() 基本:使用随机数时,经常见到的是C标准库提供的函数rand(),这个函数会生成一个0到RAND_MAX之间的一个整形数: 分布:为了得到一个给定范围内的随机数,通常会对生成的随机数取余: ...
- mybatis级联查询,多对一查询问题
在使用Mybatis进行多表级联查询时遇到了一个问题:查询结果只有一项,但正确结果是两项.经测试,SQL语句本身没有问题. 在SQL映射文件(XML)中: <!-- 级联查询数据 --> ...
- win10系统安装VMware虚拟机软件以及linux系统
一.安装VMware 1.在VMware官网下载VMware Workstation Pro 15.5.1 下载地址:https://my.vmware.com/cn/web/vmware/detai ...
- CentOS6.5安装指定的PHP版本(php5.5)(转)
查询是否安装有php #rpm -qa|grep php 删除之前安装的php版本 (yum install 安装) #rpm -e php-fpm-5.3.3-47.el6.x86_64 --nod ...