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. bootstrap中container和container-fluid的区别与用法

    对bootstrap框架有一定了解的朋友都知道,一般页面布局中的开头会使用到container或container-fluid类,那么它们有什么区别呢?不急!下面为您讲解. 我们先来看看官方对这两个类 ...

  2. Ubuntu 自动获取ip地址

    $ sudo dhclient -r               //release ip 释放IP$ sudo dhclient                  //获取IP手動使用 DHCP 自 ...

  3. 使用SharePreferences存取数据(慕课笔记 )

    0.视频地址:http://www.imooc.com/video/3265 1.使用SharePreferences存取数据: public class MainActivity extends A ...

  4. 【extjs6学习笔记】1.4 初始:ajax请求django应用

    使用sencha创建应用,默认如下: personnel数据使用的是本地数据 做以下修改,使用ajax 启动时会报404[此次调用是使用nginx部署] django应用app_jiake中,修改vi ...

  5. java控制远程ssh-JSCH(二)

    github: https://github.com/wengyingjian/ssh-java-demo.git 这次找到了一套新的api,叫jsch.网上查了一下,顺便把官网的几个demo给一通拿 ...

  6. Outlook 2016 自动发送/接收无法正常工作

    如果您的自动/发送接收由于某种原因停止工作,可能会非常令人沮丧,因为您必须记住手动执行发送/接收(F9).如果您遇到Outlook无法自动发送或接收电子邮件的问题,可以尝试以下几项操作. #1 发送/ ...

  7. [CV笔记]inRange对图像进行分割

    先把图像转为hsv空间,然后对图像进行inrange取到hsv范围内的图像,我这里要做的是取到图中的几个白色区域以及里面的手写数字,方法可能不是最好的,因为刚入门cv没几天,先试着用所学取到这几个区域 ...

  8. SG函数入门&&HDU 1848

    SG函数 sg[i]为0表示i节点先手必败. 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3. ...

  9. MVC和MVP到底有什么区别呢?

    MVC和MVP到底有什么区别呢?   MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写 MVP 全称:Model-V ...

  10. (转发)IOS动画中的枚举UIViewAnimationOptions

    若本帖转自(博客园·小八究):http://www.cnblogs.com/xiaobajiu/p/4084747.html 可怜目前天朝搜不到什么有价值的东西方便学习,在这里方便初学者. 首先这个枚 ...