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

The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers l i and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= l i <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered l i, l i+1 ,... , ri.

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
 #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的更多相关文章

  1. 线段树---poj2528 Mayor’s posters【成段替换|离散化】

    poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要 ...

  2. poj2528 Mayor's posters(线段树之成段更新)

    Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Descr ...

  3. poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)

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

  4. POJ2528 Mayor&#39;s posters 【线段树】+【成段更新】+【离散化】

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

  5. poj2528 Mayor's posters(线段树区间覆盖)

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

  6. POJ2528 Mayor's posters —— 线段树染色 + 离散化

    题目链接:https://vjudge.net/problem/POJ-2528 The citizens of Bytetown, AB, could not stand that the cand ...

  7. [POJ2528]Mayor's posters(离散化+线段树)

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

  8. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  9. [poj2528]Mayor's posters

    题目描述 The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campa ...

随机推荐

  1. docker——harbor

    为什么要用harbor? 在实际生产运维中,往往需要把镜像发布到几十.上百台或更多的节点上.这时单台Docker主机上镜像已无法满足,项目越来越多,镜像就越来越多,都放到一台Docker主机上是不行的 ...

  2. 深入理解计算机系统 第八章 异常控制流 part2

    关于进程,需要关注其提供给应用程序的两个关键抽象: 1.一个独立的逻辑控制流,它提供一个假象,好像我们的程序独占地使用处理器 2.一个私有的地址空间,它提供一个假象,好像我们的程序独占地使用内存系统 ...

  3. (Codeforce)Correct Solution?

    One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and g ...

  4. mysql查询不重复的行内容,不重复的记录数.count,distinct

    有这么一个表 记录了id, p_id, p_name , p_content , p_time 1  343        aaa            aaaaaa   2012-09-01 2   ...

  5. B2B电商正在向一个新的方向转变

    在互联网+.中国制造2025等国家战略规划的不断催发下,淡出舆论风口多时的B2B电商,开始重新回归公众视野,B2B行业也就此得到一剂强心剂.不过值得关注的是,B2B平台商业模式已经开始发生变革. 互联 ...

  6. nyoj 66-分数拆分 (Java,暴力)

    66-分数拆分 内存限制:64MB 时间限制:3000ms 特判: No 通过数:7 提交数:9 难度:1 题目描述: 现在输入一个正整数k,找到所有的正整数x>=y,使得1/k=1/x+1/y ...

  7. nyoj 73-比大小 (Java, 高精度)

    73-比大小 内存限制:64MB 时间限制:3000ms 特判: No 通过数:15 提交数:64 难度:3 题目描述: 给你两个很大的数,你能不能判断出他们两个数的大小呢? 比如1234567891 ...

  8. vue中动态加载img

    想实现动态加载图片,当点击“首页”时,图片变色 代码如下: <mt-tabbar v-model="selected" fixed class="border-1p ...

  9. python脚本编写(纯干货)

    写博客的经验不是很多,写的不好或者有什么建议请留言或者联系作者 文章所有权归作者所有,转载转发请联系作者,侵权必纠. 废话不多说,直接开始吧! python脚本的作用也就不说了,首先是一个reques ...

  10. Nginx+SpringBoot实现负载均衡

    前言 在上一篇中介绍了Nginx的安装,本篇文章主要介绍的是Nginx如何实现负载均衡. 负载均衡介绍 介绍 在介绍Nginx的负载均衡实现之前,先简单的说下负载均衡的分类,主要分为硬件负载均衡和软件 ...