poj 2528 Mayor's posters 线段树区间更新
Mayor's posters
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://poj.org/problem?id=2528
Description
- 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
There will be several test cases in the input. Each test case consists of N + 1 lines where N (1 ≤ N ≤ 200,000) is given in the first line of the test case. The next N lines contain the pairs of values Posi and Vali in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of Posi and Vali are as follows:
- Posi ∈ [0, i − 1] — The i-th person came to the queue and stood right behind the Posi-th
person in the queue. The booking office was considered the 0th person
and the person at the front of the queue was considered the first person
in the queue. - Vali ∈ [0, 32767] — The i-th person was assigned the value Vali.
There no blank lines between test cases. Proceed to the end of input.
Output
The picture below illustrates the case of the sample input.
Sample Input
5
1 4
2 6
8 10
3 4
7 10
Sample Output
HINT
题意
一个区间贴海报,然后问你在最后,能看见多少个海报
题解:
就单纯的区间更新呀,然后跑一发线段树就好
需要离散化做
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
vector<int> p;
map<int,int>H;
struct node
{
int l,r,v;
};
node a[maxn*];
struct qu
{
int x,y;
}q[maxn];
int flag[maxn];
void build(int x,int l,int r)
{
a[x].l=l,a[x].r=r;
a[x].v=;
if(l==r)
return;
int mid=(l+r)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
}
void relax(int x)
{
if(a[x].v)
{
a[x<<].v=a[x].v;
a[x<<|].v=a[x].v;
a[x].v=;
}
}
void update(int st,int ed,int x,int val)
{
int l=a[x].l,r=a[x].r;
if(st<=l&&r<=ed)
a[x].v=val;
else
{
relax(x);
int mid=(l+r)>>;
if(st<=mid)update(st,ed,x<<,val);
if(ed>mid)update(st,ed,x<<|,val);
}
}
void query(int x,int st,int ed)
{
int l=a[x].l,r=a[x].r;
if(a[x].v!=||l==r)
{
flag[a[x].v]=;
return;
}
query(x<<,st,ed);
query(x<<|,st,ed);
}
int main()
{
int t=read();
while(t--)
{
H.clear(),p.clear();
int n=read();
for(int i=;i<n;i++)
{
q[i].x=read(),q[i].y=read();
p.push_back(q[i].x);
p.push_back(q[i].y);
}
for(int i=;i<=n;i++)
flag[i]=;
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
for(int i=;i<p.size();i++)
H[p[i]]=i+;
build(,,p.size());
for(int i=;i<n;i++)
update(H[q[i].x],H[q[i].y],,i+);
query(,,p.size());
int ans=;
for(int i=;i<=n;i++)
if(flag[i])
ans++;
printf("%d\n",ans);
}
}
poj 2528 Mayor's posters 线段树区间更新的更多相关文章
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- poj 2528 Mayor's posters(线段树)
题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- ogg使用语句
create tablespace ogg datafile '/oracle/oradata/DRMT/ogg01.dbf' size 50M autoextend on; edit params ...
- PHP对象5: define / const /static
define定义全局常量: define('PATH', '/data/home/www'); const也是定义常量, 一般用于类中, 饰成员属性,不可以修饰方法,如下: class Test{ c ...
- python第三方库之numpy基础
前言 numpy是python的科学计算模块,底层实现用c代码,运算效率很高.numpy的核心是矩阵narray运算. narray介绍 矩阵拥有的属性 ndim属性:维度个数 shape属性:维度大 ...
- android的wake_lock介绍
Wake Lock是一种锁的机制, 只要有人拿着这个锁,系统就无法进入休眠, 可以被用户态程序和内核获得. 这个锁可以是有超时的或者是没有超时的, 超时的锁会在时间过去以后自动解锁. 如果没有锁了或者 ...
- Linux下多路径multipath配置【转】
一.multipath在redhat 6.2中的基本配置: 1. 通过命令:lsmod |grep dm_multipath 检查是否正常安装成功.如果没有输出说明没有安装那么通过yum功能安装一下 ...
- MYSQL三种安装方式--二进制包安装
1. 把二进制包下载到/usr/local/src下 2. 如果是tar.gz包,则使用tar zxvf 进行解压 如果是tar包,则可以使用tar xvf 进行解压 3. $ mv mysql-5. ...
- nginx报502修复日志
参考:https://www.baidu.com/link?url=PGd7mgvalnQp0MOVZTyDJIvr6_eJn1hmPlmsLpdj2vH6w3FzMt3pZEd_MKpoiqX1OF ...
- Eloquent中一些其他的create方法
firstOrCreate/ firstOrNew# 还有两种其它方法,你可以用来通过属性批量赋值创建你的模型:firstOrCreate 和firstOrNew.firstOrCreate 方法将会 ...
- 对于JAVA多线程卖票小程序的理解
昨天把多线程重新看了一遍,发现自己还是有许多需要理解的地方,现在写一篇总结. 一:利用继承Thread类会出现的问题: public class SellTicketsThread extends T ...
- 写在Web考试后的一点小总结
在实验室折腾附加题折腾了一个多钟没做出来……晚上回到宿舍决定再试一试,按原来的思路居然行了,目测在实验室的时候什么地方打错字了吧(心在流血) 实现晃过元素后出现跟随鼠标的悬浮窗,只有几行代码给我折腾了 ...