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. CentOS7.6手动编译httpd-2.4.25

    手动编译httpd-2.4.25 系统:CentOS7.1810 httpd:2.4.25 编译时报错解决技巧:报什么错,就装这个错误的devel,比如报http2错误,就yum search htt ...

  2. kubernetes实战(二十八):Kubernetes一键式资源管理平台Ratel安装及使用

    1. Ratel是什么? Ratel是一个Kubernetes资源平台,基于管理Kubernetes的资源开发,可以管理Kubernetes的Deployment.DaemonSet.Stateful ...

  3. Vue学习笔记:Vue组件的核心概念(下)

    1.双向绑定和单向数据流: 本质上还是单向数据流 视图<——>数据 v-model:仅仅是一个简写,用更少代码去实现功能. 自定义事件 .sync 修饰符 2.虚拟DOM及KEY属性作用 ...

  4. iOS:应用程序扩展开发之Today扩展(Today Extesnsion)

    一.简介 iOS应用程序扩展是苹果在iOS8推出的一个新特性,可以将自定义的功能和内容扩展到应用程序之外,在之后又经过不断地优化和更新,已经成为开发中不可或缺的功能之一.扩展也是一个Target项目, ...

  5. 第一篇:jdk8下载和idea导入,java源码结构

    一.下载和导入 下载和导入到idea,完全参考文章:https://blog.csdn.net/zhanglong_4444/article/details/88967300 照做即可,详解简单到位. ...

  6. nyoj 103-A+B Problem II (python 大数相加)

    103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...

  7. fastjason常用方法

    背景 fastjson爆出重大漏洞,攻击者可使整个业务瘫痪 漏洞描述 常用JSON组件FastJson存在远程代码执行漏洞,攻击者可通过精心构建的json报文对目标服务器执行任意命令,从而获得服务器权 ...

  8. linux下制作linux系统盘(光盘、U盘)

    cdrecord制作启动光盘 首先cdrecord -scanbus输出设备列表和标识,(我的此次为5,0,0)  [ˈrekərd] 然后用cdrecord -v dev=5,0,0 -eject ...

  9. 【笔记】总结Springboot和Vue前后端分离的跨域问题

    跨域一直是个很玄学的问题,SSM的时候又得前后端一起配置,sb的时候又不用. 前端 axios普通get请求 submitForm() { var v=this; this.$axios({ meth ...

  10. 经典算法之K近邻(回归部分)

    1.算法原理 1.分类和回归 分类模型和回归模型本质一样,分类模型是将回归模型的输出离散化. 一般来说,回归问题通常是用来预测一个值,如预测房价.未来的天气情况等等,例如一个产品的实际价格为500元, ...