CF930C.Teodor is not a liar!

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor decided to share it with Sasha.

Sasha knows that Teodor likes to show off so he never trusts him. Teodor wants to prove that he can be trusted sometimes, so he decided to convince Sasha that there is no such integer point in his picture, which belongs to each segment. However Teodor is lazy person and neither wills to tell Sasha all coordinates of segments' ends nor wills to tell him their amount, so he suggested Sasha to ask him series of questions 'Given the integer point x__i, how many segments in Fedya's picture contain that point?', promising to tell correct answers for this questions.

Both boys are very busy studying and don't have much time, so they ask you to find out how many questions can Sasha ask Teodor, that having only answers on his questions, Sasha can't be sure that Teodor isn't lying to him. Note that Sasha doesn't know amount of segments in Teodor's picture. Sure, Sasha is smart person and never asks about same point twice.

小特奥多尔喜欢画画。他最钟爱的爱好是在一个巨大的区间 [1,m][1, m] 内绘制端点均为整数的线段。某天,特奥多尔注意到自己刚画出的图形具有一个有趣的性质:不存在任何一个整数点,使得该点属于图形中所有线段的交集。发现这一事实后,特奥多尔决定将它告诉萨沙。

萨沙知道特奥多尔总爱炫耀,因此从不轻易相信他。为了证明自己偶尔也值得信赖,特奥多尔决定向萨沙证实:他的图形中确实不存在一个整数点,使得该点落在每一条线段上。然而,特奥多尔是个懒人,既不愿告诉萨沙所有线段端点的坐标,也不愿透露线段的总数量;于是他提议:萨沙可以向他提出一系列形如“给定整数点 xix_i,你的图中有多少条线段包含该点?”的问题,而他则承诺如实回答所有问题。

但两个男孩都忙于学业,时间十分有限。因此,他们请你帮忙计算:萨沙最多可以向特奥多尔提出多少个问题,使得仅凭这些问题的答案,萨沙仍无法确定特奥多尔是否在说谎? 注意:萨沙并不知道特奥多尔图中线段的总数。当然,萨沙很聪明,绝不会就同一个点重复提问。

输入格式

First line of input contains two integer numbers: n and m (1 ≤ n, m ≤ 100 000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about.

_i_th of next n lines contains two integer numbers l__i and r__i (1 ≤ l__i ≤ r__i ≤ m) — left and right ends of _i_th segment in the picture. Note that that left and right ends of segment can be the same point.

It is guaranteed that there is no integer point, that belongs to all segments.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤100 0001 \leq n, m \leq 100\,000)—— 分别表示特奥多尔画作中线段的数量,以及萨沙可以询问的点的最大坐标值。

接下来的 nn 行中,第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤m1 \leq l_i \leq r_i \leq m)—— 表示画作中第 ii 条线段的左右端点。注意:线段的左右端点可能重合(即为同一点)。

保证不存在任何一个整数点,使得该点属于所有线段。

输出格式

Single line of output should contain one integer number k – size of largest set (x__i, cnt(x__i)) where all x__i are different, 1 ≤ x__i ≤ m, and cnt(x__i) is amount of segments, containing point with coordinate x__i, such that one can't be sure that there doesn't exist point, belonging to all of segments in initial picture, if he knows only this set(and doesn't know n).

输出应为一行,包含一个整数 kk——即最大集合 {(xi, cnt(xi))}\{(x_i,\ \text{cnt}(x_i))\} 的大小,其中所有 xix_i 互不相同,且满足 1≤xi≤m1 \le x_i \le m;而 cnt(xi)\text{cnt}(x_i) 表示覆盖坐标为 xix_i 的点的线段数量。该集合需满足如下条件:仅凭此集合(而不知原始线段总数 nn),无法确定原始图中不存在一个属于所有线段的公共点。

输入输出样例

  • 输入#1

    2 4
    1 2
    3 4

    输出#1

    4
  • 输入#2

    4 6
    1 3
    2 3
    4 6
    5 6

    输出#2

    5

说明/提示

First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows cnt(x__i) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment.

In second example Sasha can ask about 5 points e.g. 1, 2, 3, 5, 6, still not being sure if Teodor haven't lied to him. But once he knows information about all points in [1;6] segment, Sasha can be sure that Teodor haven't lied to him.

第一个例子展示了萨沙永远无法确定特奥多尔是否在对他撒谎的情况,因为即使他知道区间 [1;4][1;4] 中每个点的 cnt(xi)\text{cnt}(x_i),他也无法将这种情况与特奥多尔画出了整个区间 [1;4][1;4] 的情况区分开来。

第二个例子中,萨沙可以询问 5 个点(例如 1, 2, 3, 5, 61,\,2,\,3,\,5,\,6),但仍无法确定特奥多尔是否对他撒了谎。但一旦他获知了区间 [1;6][1;6] 中所有点的信息,萨沙便能确定特奥多尔没有对他撒谎。

输入解题思路,AI测评打分。不知道怎么写?

首页