POJ2528 Mayor's poster
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
Output
The picture below illustrates the case of the sample input.
Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=;
int T,N,ans,le[maxn],ri[maxn],vis[maxn];
vector<int> vec;
struct Node{
int l,r,num;
} tree[maxn<<];
int getid(int x) { return lower_bound(vec.begin(),vec.end(),x)-vec.begin()+; }
void build(int pos,int l,int r)
{
tree[pos].l=l,tree[pos].r=r;
if(l==r)
{
tree[pos].num=-;
return ;
}
int mid=(l+r)>>;
build(pos<<,l,mid);
build(pos<<|,mid+,r);
} void pushdown(int pos)
{
tree[pos<<].num=tree[pos<<|].num=tree[pos].num;
tree[pos].num=-;
} void update(int l,int r,int pos,int val)
{
if(tree[pos].l>=l&&tree[pos].r<=r)
{
tree[pos].num=val;
return ;
}
if(tree[pos].num!=-) pushdown(pos);
int mid=(tree[pos].l+tree[pos].r)>>;
if(r<=mid) update(l,r,pos<<,val);
else if(l>=mid+) update(l,r,pos<<|,val);
else update(l,mid,pos<<,val),update(mid+,r,pos<<|,val);
} void query(int l,int r,int pos)
{
if(tree[pos].num!=-)
{
if(!vis[tree[pos].num]) ans++,vis[tree[pos].num]=;
return ;
}
if(l==r) return ;
int mid=(tree[pos].l+tree[pos].r)>>;
query(l,mid,pos<<); query(mid+,r,pos<<|);
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
memset(vis,,sizeof vis);
vec.clear(); ans=;
for(int i=;i<=N;i++)
{
scanf("%d%d",&le[i],&ri[i]);
vec.push_back(le[i]);
vec.push_back(ri[i]);
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
int len=vec.size();
build(,,len);
for(int i=;i<=N;i++)
{
int l=getid(le[i]),r=getid(ri[i]);
update(l,r,,i);
}
query(,len,);
printf("%d\n",ans);
} return ;
}
POJ2528 Mayor's poster的更多相关文章
- 线段树---poj2528 Mayor’s posters【成段替换|离散化】
poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要 ...
- poj2528 Mayor's posters(线段树之成段更新)
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Descr ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- POJ2528 Mayor's posters 【线段树】+【成段更新】+【离散化】
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39795 Accepted: 11552 ...
- poj2528 Mayor's posters(线段树区间覆盖)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 50888 Accepted: 14737 ...
- POJ2528 Mayor's posters —— 线段树染色 + 离散化
题目链接:https://vjudge.net/problem/POJ-2528 The citizens of Bytetown, AB, could not stand that the cand ...
- [POJ2528]Mayor's posters(离散化+线段树)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 70365 Accepted: 20306 ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- [poj2528]Mayor's posters
题目描述 The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campa ...
随机推荐
- Unity 简记(2)--2D移动
目录 1.输入 1.1直接检测按下哪个按键 1.2.检测水平输入和垂直输入 2.移动 2.1.Transform组件 2.2.RigidBody组件 2.3.NavMeshAgent组件 2.4.Ch ...
- kafka线上滚动升级方案记录
kafka升级方案 为什么进行kafka升级 一.修改unclean.leader.election.enabled默认值Kafka社区终于下定决心要把这个参数的默认值改成false,即不再允许出现u ...
- 理解Spark运行模式(一)(Yarn Client)
Spark运行模式有Local,STANDALONE,YARN,MESOS,KUBERNETES这5种,其中最为常见的是YARN运行模式,它又可分为Client模式和Cluster模式.这里以Spar ...
- nyoj 62-笨小熊(以对应数组中的ASC位 + 1)
62-笨小熊 内存限制:64MB 时间限制:2000ms Special Judge: No accepted:15 submit:43 题目描述: 笨小熊的词汇量很小,所以每次做英语选择题的时候都很 ...
- Python3.7.1学习(八) Python访问SQL Server数据库
一.pip install pymssql即可安装pymssql库 二.Python连接SQL Server数据库 实例代码如下: # -*- coding:utf-8 -*-"&q ...
- mysql数据库如何赋予远程某个IP 访问权限
1.授权用户root使用密码jb51从任意主机连接到mysql服务器: 代码如下: GRANT ALL PRIVILEGES ON *.* TO 'ROOT'@'%' IDENTIFIED BY 'j ...
- 痞子衡嵌入式:飞思卡尔Kinetis系列MCU启动那些事(10)- KBOOT特性(可靠升级)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔Kinetis系列MCU的KBOOT之可靠升级(Reliable Update)特性. 所谓可靠升级机制,即在更新Applica ...
- ZeroC ICE的远程调用框架 ServantLocator与Locator
ServantLocator定位的目标是Servant,而Locator定位的目标是“Ice Object”,即一个可定位的“Ice Object”代理.Servant是::Ice::Object的继 ...
- python中的__call__方法
在Python中,函数其实是一个对象: >>> f = abs >>> f.__name__ 'abs' >>> f(-) 由于 f 可以被调用, ...
- python 安装resquest
本文链接:https://blog.csdn.net/charlotte1516/article/details/91991848 搬运是为了怕原链接失效,建议浏览原链接. 1.首先在开始栏搜索cmd ...