CF863E.Turn Off The TV

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time l__i till moment r__i, inclusive.

Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.

Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.

卢巴再次需要你的帮助!卢巴有 nn 台电视机。她知道第 ii 台电视机将在时间区间 [li,ri][l_i, r_i](含端点)内正常工作。

卢巴希望关闭其中一台电视机,以腾出一个电源插座。我们称某台电视机为冗余的,当且仅当关闭它之后,至少有一台电视机正在工作的整数时刻总数不会减少。如果卢巴被迫关闭一台非冗余的电视机,她会非常不开心。

请帮卢巴找出一台冗余电视机的下标(索引)。若不存在冗余电视机,则输出 −1-1。

输入格式

The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.

Then n lines follow, each of them containing two integer numbers l__i, r__i (0 ≤ l__i ≤ r__i ≤ 109) denoting the working time of i-th TV set.

第一行包含一个整数 $ n (( 1 \leq n \leq 2 \cdot 10^5 $)—— 表示电视机的数量。

接下来有 $ n $ 行,每行包含两个整数 $ l_i 、、 r_i (( 0 \leq l_i \leq r_i \leq 10^9 $),表示第 $ i $ 台电视机的工作时间区间。

输出格式

If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).

If there are multiple answers, print any of them.

如果没有冗余的电视机,则输出 -1。否则,输出任意一个冗余电视机的索引(电视机的索引从 1 到 nn)。

如果存在多个答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    1 3
    4 6
    1 7

    输出#1

    1
  • 输入#2

    2
    0 10
    0 10

    输出#2

    1
  • 输入#3

    3
    1 2
    3 4
    6 8

    输出#3

    -1
  • 输入#4

    3
    1 2
    2 3
    3 4

    输出#4

    2

说明/提示

Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).

Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].

考虑第一个样例。最初,至少有一台电视处于工作状态的所有整数时刻构成区间 [1;7]。容易看出,若关闭第一台电视(或第二台电视),该区间不会发生变化。

注意,在第四个样例中,你可以关闭第二台电视,因为即使没有它,所有至少有一台电视处于工作状态的整数时刻仍构成区间 [1;4]。

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

首页