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张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...
随机推荐
- 76.ZYNQ-用PS控制DDR3内存读写
本编文章的目的主要用简明的方法对DDR3进行读写,当然这种方式每次读写都需要CPU干预,效率是比较低的,但是这是学习的过程吧. 本系列文章尽可能的让每一个实验都相对独立,过程尽可能保证完整性,保证实验 ...
- 用于启动 Windows Phone 8 内置应用的 URI 方案
本主题列出了可用于启动内置应用的 URI 方案.许多内置于 Windows Phone 的应用,都可以通过调用 LaunchUriAsync(Uri) 和传入一个使用与要启动应用相关的方案的 URI, ...
- 接口测试(概念、Postman、SoapUI、jmeter)
一.什么是接口测试 接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑 ...
- linux自动获得mac地址,修改网络配置
1.修改网络配置,自动获得mac地址 删除 /etc/udev/rules.d/70-persistent-net.rules 文件 删除 /etc/sysconfig/network-scripts ...
- JSP、EL表达式、JSTL
JSP 1.什么是jsp? Java Server Pages: java服务器端页面.可以理解为一个特殊的页面,其中既可以指定定义html标签,又可以定义java代码.其本质就是一个Servlet. ...
- 20165301 2017-2018-2 《Java程序设计》第七周学习总结
20165301 2017-2018-2 <Java程序设计>第七周学习总结 教材学习内容总结 第十一章:JDBC与MySQL数据库 MySQL数据库管理系统 启动MySQL数据库服务器 ...
- covariance matrix 和数据分布情况估计
how to get data covariance matrix: http://stattrek.com/matrix-algebra/covariance-matrix.aspx meaning ...
- find tar排除指定文件或目录操作及查找文件内容关键字
1.find查找排除单个目录 查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk find . -path "./sk" -prune -o -name "*. ...
- Python--re模块的findall等用法
1)正则表达式含义 . # 点可代表一切字符 \ # 起转义作用 [...] # 指代方括号中的任意字符 \d # 指代数字0-9 \D # 指代非数字 \s # 指代一切空格,包括tab制表符.空格 ...
- Expert C Programming 阅读笔记(~CH1)
P4: 好梗!There is one other convention—sometimes we repeat a key point to emphasize it. In addition, w ...