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. cocos的Director、Scence、Layer(一)---摘自于官方文档

    基本结构图(重要) Director: 有那些作用? OpenGL ES的初始化,场景的转换,游戏暂停继续的控制,世界坐标和GL坐标之间的切换,对节点(游戏元素)的控制,游戏数据的保存调用,屏幕尺寸的 ...

  2. SQLAlchemy的基本使用

    一.介绍 SQLAlchemy是一种ORM(Object-Relational Mapping)框架,用来将关系型数据库映射到对象上.该框架建立在DB API之上,将类和对象转化成SQL,然后使用AP ...

  3. 激光推送报错:APNs is not available,please check your provisioning profile and certification 和 设置别名问题 app not registed, give up set tag:

    前几天,项目中用到了推送功能,就集成了激光,遇到了2个问题,就给大家分享一下, 第一个问题: 在集成的过程是按照激光的文档做的,但是最后配置完了,一运行,就打印出这么一句话, APNs is not ...

  4. 两个对象值转换的方法(BeanUtils.copyProperties与JSONObject.parseObject对比)

    将源对象赋值到目标对象方法: 方法一:BeanUtils.copyProperties(源对象, 目标对象); //org.springframework.beans.BeanUtils 方法二:目标 ...

  5. sqlite 新建实体时出错

    解决方式 手动下载 问题原因

  6. 《毛毛虫组》【Alpha】Scrum meeting 3

    第二天 日期:2019/6/16 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: 货物入库管理模块设计: (1)对数据库表--tb_InStore进行修改并完善: (2)学习SQL Se ...

  7. cocos2dx for lua 简单的翻牌动画

    local x = 20 local y = display.height/2 for i = 1,16 do--创建16张 local cardFg = display.newSprite(&quo ...

  8. Sum All Numbers in a Range-freecodecamp算法题目

    Sum All Numbers in a Range 要求 给你一个包含两个数字的数组.返回这两个数字和它们之间所有数字的和. 最小的数字并非总在最前面. 思路 定义结果变量num 在for循环中,i ...

  9. centos6启动故障排除

    centos6中boot文件被全部删除的故障排除 /boot文件里关于启动的核心文件有三个,/vmlinuz-2.6.32-696.e16.x86_64,initramfs-2.6.32-696.el ...

  10. iPhone如何设置自定义铃声?无需连接电脑,轻松几步就搞定!

    转载自: https://baijiahao.baidu.com/s?id=1594988016778457969&wfr=spider&for=pc 受够了iPhone自带的千篇一律 ...