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

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 li 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 <= li <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered li, li+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

太令人窒息了!!!!!查错两小时!!!!!
很容易看得出来这是个线段树,每次贴一张就相当于一次区间修改,完了之后刷一遍看有多少种.....
but....
仅仅这样是不够的,数据范围疯狂暗示我们它想要离散化
然后就完了
一定要注意不要写错板子啊啊啊啊啊啊啊
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define N 200010
#define lc p<<1
#define rc p<<1|1
using namespace std;
int n,t,m,tot;
int ll[N],rr[N],a[N],col[N],ans;
bool vis[N];
struct tree
{
int l,r;
int lazy,c;
}T[N*];
inline void pushnow(int p,int c)
{
T[p].lazy=c;
T[p].c=c;
}
inline void pushup(int p)//√
{
if(!T[lc].c||!T[rc].c||T[lc].c!=T[rc].c) T[p].c=;
else T[p].c=T[rc].c;
}
inline void pushdown(int p)
{
if(T[p].lazy!=-)
{
pushnow(lc,T[p].lazy);
pushnow(rc,T[p].lazy);
T[p].lazy=-;
}
}
void build(int p,int l,int r)//√
{
T[p].l=l; T[p].r=r;
if(l==r)
{
T[p].c=-;
T[p].lazy=-;
return;
}
int mid=(T[p].l+T[p].r)>>;
build(lc,l,mid); build(rc,mid+,r);
pushup(p);
}
void update(int p,int ql,int qr,int v)
{
if(ql<=T[p].l&&T[p].r<=qr)//!!!!!!!!!!!!!!!!!!
{
pushnow(p,v);
return;
}
pushdown(p);
int mid=(T[p].l+T[p].r)>>;
if(ql<=mid) update(lc,ql,qr,v);
if(qr>mid) update(rc,ql,qr,v);
pushup(p);
} void query(int p,int ql,int qr)
{
if(T[p].c==-) return;
else if(T[p].c>)
{
col[T[p].c]=;
return;
}
int mid=(T[p].l+T[p].r)>>;
pushdown(p);
if(ql<=mid) query(lc,ql,qr);
if(qr>mid) query(rc,ql,qr);
}
int main()
{
scanf("%d",&t);
while(t--)
{
int ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int pl,pr;
scanf("%d%d",&pl,&pr);
ll[i]=pl; rr[i]=pr;
a[i*-]=pl;a[i*]=pr;
}
sort(a+,a++*n);
m=unique(a+,a++*n)-(a+);
tot=m;
for(int i=;i<m;i++)
if(a[i]+<a[i+])
a[++tot]=a[i]+;
sort(a+,a++tot);
build(,,tot);
memset(col,,sizeof(col));
for(int i=;i<=n;i++)
{
int x=lower_bound(a+,a++tot,ll[i])-a;
int y=lower_bound(a+,a++tot,rr[i])-a;
//cout<<x<<" "<<y<<endl;
update(,x,y,i);
}
query(,,tot);
for(int i=;i<=n;i++)
if(col[i]) ans++;
printf("%d\n",ans);
}
return ;
}

这是一篇代码

 

【SDOJ 3741】 【poj2528】 Mayor's posters的更多相关文章

  1. POJ2528 Uva10587 Mayor's posters

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

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

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

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

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

  4. 【poj2528】Mayor's posters

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

  5. 【线段树】Mayor's posters

    [poj2528]Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 66154   Accept ...

  6. 【POJ】2528 Mayor's posters ——离散化+线段树

    Mayor's posters Time Limit: 1000MS    Memory Limit: 65536K   Description The citizens of Bytetown, A ...

  7. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  8. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  9. 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】

    [英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...

随机推荐

  1. SPEC CPU 使用简介

    SPEC CPU2000简介 SPEC CPU2000是由标准性能评价机构“The Standard Performance Evaluation Corporation (SPEC)”开发的用于评测 ...

  2. dstat工具使用介绍

    一.dstat工具多功能系统资源统计生成工具.获取信息类似top.free.iostat.vmstat等多个工具的合集,所以也称为vmstat.iostat.ifstat等工具替代品,其结果可以存储成 ...

  3. selenium-Python之上传文件

    对于web 页面的上传功能实现一般有一下两种方式 普通上传:普通的附件上传是将本地文件的路径作为一个值放在input标签中,通过form表单将这个值提交给服务器 插件上传:一般是指基于flash.ja ...

  4. HDU 3652 B-number (数位DP,入门)

    题意: 如果一个整数能被13整除,且其含有子串13的,称为"B数",问[1,n]中有多少个B数? 思路: 这题不要用那个DFS的模板估计很快秒了. 状态设计为dp[位数][前缀][ ...

  5. (四)SpringMVC之使用cookie实现记住密码的功能

    注意:因为实现记住密码的功能需要用到json,所以需要加上这条语句: <script type="text/javascript" src="scripts/jqu ...

  6. python爬虫之路——初识基本页面构造原理

    通过chrome浏览器的使用简单介绍网页构成 360浏览器使用右键审查元素,Chrome浏览器使用右键检查,都可查看网页代码. 网页代码有两部分:HTML文件和CSS样式.其中有<script& ...

  7. springboot 内置tomcat maxPostSizs 无法设置

    ++++++++++++++++++ RT +++++++++++++++++ 如下代码方可解决: /** * tomcat配置类 * 解决post数据体大于2048kb无法接收问题 * 解决tomc ...

  8. Codevs1080 线段树练习

    题目描述 Description 一行N个方格,开始每个格子里都有一个整数.现在动态地提出一些问题和修改:提问的形式是求某一个特定的子区间[a,b]中所有元素的和:修改的规则是指定某一个格子x,加上或 ...

  9. spring bean的介绍以及xml和注解的配置方法

    5.Bean 下边我们来了解一下Bean的: Bean的作用域Bean的生命周期Bean的自动装配Resources和ResourceLoader 5.1Bean容器的初始化 Bean容器的初始化 两 ...

  10. 03IO端口寻址和访问控制方式

    1. I/O端口和寻址 CPU 为了访问 I/O 接口控制器或者控制卡上的数据和状态信息,需要首先指定他们的地址.这种地址就称为I/O端口地址或简称端口.通常一个 I/O 控制器包含访问数据的数据端口 ...