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 ...
 
随机推荐
- Python 基础之 I/O 模型
			
一.I/O模型 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接 ...
 - hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
			
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
 - ubuntu 18 怎样对Windows进行远程桌面控制
			
ubuntu 18 怎样对Windows进行远程桌面控制: 1. 先安装一个redesktop 工具(sudo apt-get install redesktop) 2. 在通过 redesktop ...
 - C语言作业|08
			
问题 答案 这个作业的属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/9977 我 ...
 - python:爬虫0
			
什么是网页爬虫,也叫网页蜘蛛.把互联网比作一个蜘蛛网,有好多节点,这个蜘蛛在网上爬来爬去,对对网页中的每个关键字进行建立索引,然后建立索引数据库,经过复杂的排序算法后,这些算法的结果将按照相关度的高低 ...
 - vue的一些小记录
			
1.在一个标签中,不推荐v-for 与 v-if 同时用 //当 v-if 与 v-for,v-for 具有比 v-if 更高的优先级. //当它们处于同一节点(同一标签 一起使用时),v-for 的 ...
 - 🙀Java 又双叒叕发布新版本,这么多版本如何灵活管理?
			
文章来源:http://1t.click/bjAG 前言 不知不觉 JDK13 发布已有两个月,不知道各位有没有下载学习体验一番?每次下载安装之后,需要重新配置一下 Java 环境变量.等到运行平时的 ...
 - 网络图片的获取以及二级缓存策略(Volley框架+内存LruCache+磁盘DiskLruCache)
			
在开发安卓应用中避免不了要使用到网络图片,获取网络图片很简单,但是需要付出一定的代价——流量.对于少数的图片而言问题不大,但如果手机应用中包含大量的图片,这势必会耗费用户的一定流量,如果我们不加以处理 ...
 - python3之递归实例
			
一.利用递归求: 1+2+3+4+5...+n的前n项和 def recursion_sum_1(n): #当n = 1:和为1 #否则,n的和等同于 n + (n -1) if n == 1: re ...
 - scrapy框架介绍及安装
			
什么是scrapy框架? scrapy框架的安装 1.windowes下的安装 Python 2 / 3升级pip版本: pip install --upgrade pip 通过pip 安装 Scra ...