Mayor's posters

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://poj.org/problem?id=2528

Description

The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules:

  • 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 ≤ iN). 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

For each input data set print the number of visible posters after all the posters are placed.

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

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 线段树区间更新的更多相关文章

  1. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  2. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  3. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 ...

  4. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  5. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  6. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  7. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  8. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  9. poj 2528 Mayor's posters(线段树)

    题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...

随机推荐

  1. IE9 下 ellipsis bug fix

    fiddle: http://jsfiddle.net/tagliala/TtbuG/10/ original: https://github.com/FortAwesome/Font-Awesome ...

  2. device tree --- #address-cells and #size-cells property

    device tree source Example1 / { #address-cells = <0x1>; // 在 root node 下使用 1 個 u32 來代表 address ...

  3. Linux sqlite3基本命令

    简介sqlite3一款主要用于嵌入式的轻量级数据库,本文旨在为熟悉sqlite3基本命令提供技术文档. 备注:本文所有操作均在root用户下进行. 1.安装sqlite3 ubuntu下安装sqlit ...

  4. c++各种排序的简单实现

    /* 直插排序 */ void InsertSort(vector<int> &arr){ for(int i = 1;i < arr.size();++i){ for(in ...

  5. 使用coding云作为git远程库

    1.在命令行中创建GIT仓库 mkdir DriveAssistant cd DriveAssistant git init echo "# DriveAssistant" > ...

  6. CTF中的EXP编写技巧 zio库的使用

    zio库没有提供文档 这个是官方给出的一个例子程序 from zio import * io = zio('./buggy-server') # io = zio((pwn.server, 1337) ...

  7. 回文词(UVa401)

    详细题目描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  8. [实战]MVC5+EF6+MySql企业网盘实战(14)——思考

    写在前面 从上面更新编辑文件夹,就一直在思考一个问题,之前编辑文件夹名称,只是逻辑上的修改,但是保存的物理文件或者文件夹名称并没有进行修改,这样就导致一个问题,就是在文件或者文件夹修改名称后就会找不到 ...

  9. CyclicBarrier 简介

    CyclicBarrier 简介 CyclicBarrier 的字面意思是可循环使用(Cyclic)的屏障(Barrier). 它要做的事情是,让一组线程到达一个屏障(也可以叫同步点)时被阻塞,直到最 ...

  10. SQL join关键字

    如果一张表有很多个字段可能填入起来十分的困难复杂,不如把它拆分成两个表,然后查看的时候合并起来. 比如我要记录学生的姓名,班级,成绩,父母的电话号码,那么我们可以创建一个表1 储存学生的姓名班级成绩, ...