Mayor's posters
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 70365   Accepted: 20306

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

[线段树+离散化]

有关这道题的离散化我说一下,例如海报区间为[1,10],[1,4],[6,10],离散化后区间为[1,4],[1,2],[3,4],这样第一张海报就被覆盖掉了,实际上第一张并没有被覆盖。

解决方法就是在[1,10]中间加一个[1,2]&[2,10]这样离散化就会出现一个新的离散化区间。

但下面的标程是luogu的3740,poj的只需要修改一下。
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=,M=; int n,m,Ans,A[M],B[M];
bool flag,colored[N<<]; int read()
{
int now=;char c=getchar();
while(c<''||c>'')c=getchar();
while(c>=''&&c<='')now=(now<<)+(now<<)+c-'',c=getchar();
return now;
} void PushUp(int rt)
{
colored[rt]= colored[rt<<]&&colored[rt<<|];
} void Modify(int l,int r,int rt,int L,int R)
{
if(colored[rt]) return;
if(L<=l && r<=R)
{
flag=;colored[rt]=;
return;
}
int m=(l+r)>>;
if(L<=m) Modify(l,m,rt<<,L,R);
if(m<R) Modify(m+,r,rt<<|,L,R);
PushUp(rt);
} int main()
{
n=read();m=read();
for(int i=;i<=m;i++)
A[i]=read(),B[i]=read(); for(int i=m;i>=;i--)
{
flag=;
Modify(,n,,A[i],B[i]);
if(flag) ++Ans;
}
printf("%d",Ans);
return ;
}

[POJ2528]Mayor's posters(离散化+线段树)的更多相关文章

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

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

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

    http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...

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

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  4. POJ2528 Mayor's posters(线段树+离散化)

    题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...

  5. Mayor's posters(离散化线段树)

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

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

    恩,这区间范围挺大的,需要离散化.如果TLE,还需要优化一下常数. AC代码 #include <stdio.h> #include <string.h> #include & ...

  7. POJ2528 Mayor's posters(线段树&区间更新+离散化)题解

    题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...

  8. POJ2528 Mayor's posters(线段树染色问题+离散化)

    题目大意:有t组数据,每组数据给你n张海报(1<=n<=10000),下面n组数据分别给出每张海报的左右范围(1 <= l <= r <= 10000000),下一张海报 ...

  9. poj2528 Mayor's posters【线段树】

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

  10. POJ-2528 Mayor's posters (离散化, 线段树)

    题目传送门: POJ-2528 题意就是在一个高度固定的墙面上贴高度相同宽度不同的海报,问贴到最后还能看到几张?本质上是线段树区间更新问题,但是要注意的是题中所给数据范围庞大,直接搞肯定会搞出问题,所 ...

随机推荐

  1. 【风马一族_php】NO4_php基础知识

    原文来自:http://www.cnblogs.com/sows/p/6017018.html(博客园的)风马一族 侵犯版本,后果自负 回顾 运算符:算术运算符.逻辑运算符.比较运算符.位运算符.赋值 ...

  2. navicat for mysql 在Mac上安装后没有连接列表,就是左边的那一列连接项目怎么办?

    在连接数处打对勾就可以了

  3. Java练习 SDUT-2499_数字

    数字 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 定义f(x) = {比x小,不可以被x整除并且不和x互质的数的个数 ...

  4. du,df区别

    1.记住命令 du:disk Usage -h, --human-readable print sizes in human readable format df:disk free 2.区别 du ...

  5. COGS 775 山海经

    COGS 775 山海经 思路: 求最大连续子段和(不能不选),只查询,无修改.要求输出该子段的起止位置. 线段树经典模型,每个节点记录权值和sum.左起最大前缀和lmax.右起最大后缀和rmax.最 ...

  6. @bzoj - 4380@ [POI2015] Myjnie

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 有 n 家洗车店从左往右排成一排,每家店都有一个正整数价格 p[ ...

  7. vue-awesome-swiper轮播插件的使用方法及问题。

    在使用vue-awesome-swiper的时候,遇到一些问题,记录一下!       1.npm 安装 npm install vue-awesome-swiper --save 2.使用 在mai ...

  8. 最优化方法系列:Adam+SGD-AMSGrad 重点

    https://blog.csdn.net/wishchin/article/details/80567558 自动调参的Adam方法已经非常给力了,不过这主要流行于工程界,在大多数科学实验室中,模型 ...

  9. oracle sum()聚合函数

    原文链接:https://blog.csdn.net/cizatu5130/article/details/100291347 oracle sum()聚合函数 2016-05-13 20:08:00 ...

  10. logback 打印mybatis sql mybatis 日志打印sql语句和返回结果

    logback 打印sql语句: 在logback日志文件中开启debug模式 <logger name="com.ibatis" level="DEBUG&quo ...