UVA10587 Mayor‘s posters 题解 线段树 离散化

UVA10587 Mayor’s posters

传送门(有亿点慢,需要耐心)

PDF
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 e l e c t o r a l electoral electoral w a l l wall 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 ( b y t e byte 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 c c giving the number of cases that follow. The first line of data for a single case contains number 1 ≤ n ≤ 10000 1\le n\le 10000 1n10000. The subsequent n lines describe the posters in the order in which they were placed. The i i i-th line among the n lines contains two integer numbers l i l_i li and r i r_i 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\le i\le n 1in, 1 ≤ l i ≤ r i ≤ 10000000 1\le l_i\le r_i\le 10000000 1liri10000000. After the i i i-th poster is placed, it entirely covers all wall segments numbered l i , l i + 1 , . . . , r i l_i, l_i+1 ,... , r_i li,li+1,...,ri.

Output

For each input data set print the number of visible posters after all the posters are placed.

Note: The picture below illustrates the case of the sample input.
在这里插入图片描述

Sample

input

1
5
1 4
2 6
8 10
3 4
7 10

output

4

题目翻译

AB 省 B y t e Byte Byte 镇的市民们无法忍受市长竞选活动中的候选人随心所欲地在各个地方张贴选举海报。市议会最终决定建造一面选举墙,用于张贴海报,并出台了以下规则:

  • 每位候选人只能在墙上张贴一张海报。
  • 所有海报的高度相同,等于墙的高度;海报的宽度可以是任意整数字节(字节是 B y t e Byte Byte 镇的长度单位)。
  • 墙面被分成若干段,每段的宽度为一个字节。
  • 每张海报必须完全覆盖连续的墙段。

他们建造了一堵长达 10000000 b y t e byte byte 的墙(这样所有候选人都有足够的位置)。竞选活动重新开始后,候选人开始在墙上张贴海报,他们的海报宽度相差很大。此外,候选人开始将自己的海报张贴在已被其他海报占据的墙面上。 B y t e Byte Byte 镇的每个人都很好奇,在选举前的最后一天,谁的海报还

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值