Mayor's posters
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 45703   Accepted: 13239

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

用 col[rt] 来记录如今是什么颜色, -1 表示这个区间有多个颜色..

区间的范围比较大,先对它进行离散一下。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
typedef long long LL;
const int oo = 1e9+;
const double PI = acos(-1.0);
const double eps = 1e- ;
const int N = ;
const int mod = ;
int n , m ;
LL col[N<<] , tot ;
bool tag[N<<] ; void Down( int l , int r , int rt ) {
if( col[rt] != - ) col[lr] = col[rr] = col[rt] ;
}
void Up( int rt ){
if( col[lr] == col[rr] && col[lr] != - ) col[rt] = col[lr];
else col[rt] = - ;
}
void build( int l , int r , int rt ){
col[rt] = - ;
if( l == r ) return ;
int mid = (l+r)>>;
build(lson),build(rson);
}
void update( int l , int r , int rt , int L , int R , int c ) {
// cout << L <<' ' << R << ' ' << l << ' ' << r << endl ;
if( L == l && r == R ) {
col[rt] = c ; return ;
}
if( col[rt] == c ) return ;
else Down( l,r,rt ) , col[rt] = - ;
int mid = (l+r)>>;
if( R <= mid ) update(lson,L,R,c);
else if( L > mid ) update(rson,L,R,c);
else update(lson,L,mid,c) , update(rson,mid+,R,c);
Up(rt);
}
LL query( int l , int r , int rt , int x ) {
if( col[rt] != - ) return col[rt];
Down(l,r,rt);
int mid = (l+r)>>;
if( x <= mid ) return query(lson,x);
else return query(rson,x);
}
struct node {
int num , new_num , id ;
}e[N];
bool cmp1( const node &a , const node &b ) { return a.num < b.num ; }
bool cmp2( const node &a , const node &b ) { return a.id < b.id ; } int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif // LOCAL
int _ ; scanf("%d",&_);
while( _-- ) {
memset( tag , false , sizeof tag );
tot = ; scanf("%d",&n);
for( int i = ; i < n ; ++i ) {
scanf("%d",&e[tot].num); e[tot].id = tot ; tot++;
scanf("%d",&e[tot].num); e[tot].id = tot ; tot++;
}
sort( e , e + tot , cmp1 );
e[].new_num = ;
for( int i = ; i < tot ; ++i )
e[i].new_num = (e[i].num == e[i-].num?e[i-].new_num:e[i-].new_num+);
sort( e , e + tot , cmp2 );
n = tot+;
build(root);
for( int i = ; i < tot ; i+= ){
// cout << e[i].new_num << ' ' << e[i+1].new_num << endl ;
update(root,e[i].new_num,e[i+].new_num,i+);
}
// cout << "ok" << endl ;
for( int i = ; i <= n ; ++i ) {
// cout << query(root,i) << endl ;
int color = query(root,i) ;
if( color == - ) continue ;
tag[color] = true ;
}
int ans = ;
for( int i = ; i <= n ; ++i ) if(tag[i]) ans++;
printf("%d\n",ans);
}
}

POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)的更多相关文章

  1. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  2. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  3. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  4. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

  5. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  6. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  7. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  8. poj 2528 Mayor's posters(线段树)

    题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数 ...

  9. POJ 2528 Mayor's posters (线段树)

    题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...

随机推荐

  1. Maya2017下载安装与激活

    目录 1. 更多推荐 2. 下载地址 2.1. OneDrive 2.2. 百度云 3. 安装激活步骤 1. 更多推荐 其他Maya版本的下载与激活:https://www.cnblogs.com/c ...

  2. [CQOI2015]网络吞吐量(网络流+SPFA)

    [CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的 ...

  3. [web 安全] xxe

    一.探测漏洞 1.是否支持实体解析. 2.是否支持外部实体解析. 2.1 直接读取本地文件: 2.2 远程文件: 3.不回显错误,则用 blind xxe.(先获取本地数据,然后带着本地数据去访问恶意 ...

  4. 如何在centos7中设置redis服务器开机自启动

    1.简单说明centos7系统中有不同类型的程序,一类是操作系统的服务程序,另一类是第三方程序,而redis就是第三方程序,每次关机后开机都要手工重新启动,很麻烦,那么如何把redis设置为开机自启动 ...

  5. vue+java后台通信报403,cors解决跨域问题(该贴说的不是很清楚,不过大概如此,可再去网上查相关内容)

    前端是vue2.0,网络请求用的是axios,后端是springboot2.0 用axios向后端发送post请求,结果得到一个403无权限的错误,莫名其妙啊,我明明发送的是post请,但在chrom ...

  6. MySql 的类型和Java的类型

    参考:https://www.cnblogs.com/jerrylz/p/5814460.html 类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述           ...

  7. Solr核心(内核)

    Solr核心(内核)   Solr核心(Core)是Lucene索引的运行实例,包含使用它所需的所有Solr配置文件.我们需要创建一个Solr Core来执行索引和分析等操作. Solr应用程序可以包 ...

  8. vue实现动态显示与隐藏底部导航的方法分析

    本文实例讲述了vue实现动态显示与隐藏底部导航的方法.分享给大家供大家参考,具体如下: 在日常项目中,总有几个页面是要用到底部导航的,总有那么些个页面,是不需要底部导航的,这里列举一下页面底部导航的显 ...

  9. scau 1079 三角形(暴力)

    </pre>1079 三角形</h1></center><p align="center" style="margin-top: ...

  10. 10 Advanced Bing Search Tricks You Should Know

    Exclude Websites From Bing Search: wikipedia -wikipedia.org Excluding Keywords From Bing Search: fac ...