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. 

 
  题目大致就是说给一个线段覆盖线段,问最后没有被完全覆盖的线段的个数。
  这是第一次写离散,也是第三次写线段树的区间更新,想了好久,发现是个空线段树,只需要COL,即标记,不需要BIT来保存啥数据。
  离散的话是因为数据范围太大,只取用到的,排序后分别编号为1...N ,再用。
  (注:这个题要注意,离散的话比如3和7分别标号为4和5的话,那么如果第一个覆盖1-20,第二个覆盖1-3 , 另一个覆盖 7-10 的话,那么编号4和5都被覆盖,结果将为2,而不是正确的3 。 所以可以按照杭电那位大神的处理方法,只要3和7之间超过1,那么再加一个数4,这样的话分别编号为4,5,6就好了。)
  标记记录每次更新的为编号几。
 
代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; int COL[*];
int num[];
int num1[];
int rnum[];
int cou;
bool vis[]; int findH(int x,int L,int R)
{
int M=(L+R)/; if(rnum[M]==x)
return M; if(rnum[M]<x)
return findH(x,M+,R);
else
return findH(x,L,M);
} void pushDown(int po)
{
if(COL[po])
{
COL[po*]=COL[po];
COL[po*+]=COL[po]; COL[po]=;
}
} void update(int ul,int ur,int cha,int L,int R,int po)
{ if(ul<=L&&ur>=R)
{
COL[po]=cha; return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
update(ul,ur,cha,lson);
if(ur>M)
update(ul,ur,cha,rson); } void query(int L,int R,int po)
{
if(L==R)
{
if(COL[po])
vis[COL[po]]=; return;
} pushDown(po); int M=(L+R)/; query(lson);
query(rson);
} int main()
{
int T,N;
int a,b;
int ans=;
cin>>T; while(T--)
{
memset(COL,,sizeof(COL));
memset(vis,,sizeof(vis));
scanf("%d",&N); ans=; for(int i=;i<N;++i)
{
scanf("%d %d",&num[i*],&num[i*+]);
num1[i*]=num[i*];
num1[i*+]=num[i*+];
} sort(num,num+*N); rnum[]=num[];
cou=;
for(int i=;i<N*;++i)
{
if(num[i]==num[i-])
continue; if(num[i]-num[i-]>)
rnum[cou++]=num[i-]+; rnum[cou++]=num[i];
} for(int i=;i<N;++i)
{
a=findH(num1[i*],,cou-);
b=findH(num1[i*+],,cou-); update(a+,b+,i+,,cou,);
} query(,cou,); for(int i=;i<=N;++i)
if(vis[i])
++ans; printf("%d\n",ans);
} return ;
}

(中等) POJ 2528 Mayor's posters , 离散+线段树。的更多相关文章

  1. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

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

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

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

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

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

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  5. POJ 2528 ——Mayor's posters(线段树+区间操作)

    Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand t ...

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

    点我看题目 题意 :建一堵墙粘贴海报,每个候选人只能贴一张海报,海报的高度与墙一样高,一张海报的宽度是整数个单位,墙被划分为若干个部分,每个部分的宽度为一个单位,每张海报完全的覆盖一段连续的墙体,墙体 ...

  7. POJ 2528 Mayor's posters(线段树染色问题+离散化)

    http://poj.org/problem?id=2528 题意: 给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报. 题意:这道题目就相当于对x轴染色,然后计算出最后还能看见多少 ...

  8. POJ:2528(Mayor's posters)离散化成段更新+简单哈希

    http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the ca ...

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

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

随机推荐

  1. zzuli 1919 数列划分

    题面: Description 晴天想把一个包含n个整数的序列a分成连续的若干段,且和最大的一段的值最小,但他有强迫症,分的段数不能超过m段,然后他就不会分了...他想问你这个分出来的和最大的一段的和 ...

  2. python 中调用shell命令

    subprocess模块 根据Python官方文档说明,subprocess模块用于取代上面这些模块.有一个用Python实现的并行ssh工具—mssh,代码很简短,不过很有意思,它在线程中调用sub ...

  3. HDU 1686 Oulipo(KMP+计算匹配成功次数)

    一开始总是超时,后来发现还是方法没找对,这个跟普通KMP不太一样的就是,KMP匹配成功的时候会完全跳过已经匹配成功的匹配段,至少我掌握的是.那么如何避免这样的问题呢,举个栗子啊 原串为ABABA,模式 ...

  4. Sea.Js使用入门

    1.Sea.Js是什么 seajs相对于RequireJs与LabJS就比较年轻,2010年玉伯发起了这个开源项目,SeaJS遵循CMD规范,与RequireJS类似,同样做为模块加载器.示例 // ...

  5. HDU 3691 Nubulsa Expo

    无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  6. Javascript面向对象编程(二):构造函数的继承

    这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有一个" ...

  7. 【转】PHP里的basename函数不支持中文名的解决

    今天用到basename 函数获取文件名称时,发现如果是中文的文件名返回只有后缀的空文件名(如:.pdf)    string basename ( string path [, string suf ...

  8. JSP内置对象--pageContext对象(非常重要!!!)

    pageContext对象是javax.servlet.jsp.PageContext类的实例,只要表示的是一个jsp页面的上下文,而且功能强大,几乎可以操作各种内置对象. >forward(S ...

  9. php源码分析之base64_encode函数

    base64_encode编码规律分析 字符串长度除以3向上取整乘以4等于编码后的字符串长度 ceil(strlen($string)/3)*4 = strlen(base64_encode($str ...

  10. STM32 IAP 固件升级设计/U盘升级固件

    源:STM32 IAP 固件升级设计/U盘升级固件 固件升级的基本思路是: 将stm32 的flash划分为两个区域: 1.Bootloader区:存放bootloader的代码,bootloader ...