CF976C.Nested Segments

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a sequence _a_1, _a_2, ..., a__n of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a__i lies within segment a__j.

Segment [_l_1, _r_1] lies within segment [_l_2, _r_2] iff _l_1 ≥ _l_2 and _r_1 ≤ _r_2.

Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

给你一个一维线段序列 a1, a2, ..., ana_1, a_2, ..., a_n,编号为 11 到 nn。你的任务是找出两个不同的下标 ii 和 jj,使得线段 aia_i 完全位于线段 aja_j 内部。

线段 [l1, r1][l_1, r_1] 位于线段 [l2, r2][l_2, r_2] 内部,当且仅当 l1 ≥ l2l_1 \ge l_2 且 r1 ≤ r2r_1 \le r_2。

输出下标 ii 和 jj。若存在多个答案,输出任意一组即可。若不存在这样的答案,则输出 -1 -1。

输入格式

The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.

Each of the next n lines contains two integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ 109) — the i-th segment.

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5)——线段的数量。

接下来的 nn 行中,每行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤1091 \leq l_i \leq r_i \leq 10^9)——第 ii 条线段。

输出格式

Print two distinct indices i and j such that segment a__i lies within segment a__j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

输出两个不同的下标 ii 和 jj,使得线段 aia_i 完全位于线段 aja_j 内部。若存在多个答案,输出任意一个即可。若不存在这样的答案,则输出 -1 -1。

输入输出样例

  • 输入#1

    5
    1 10
    2 9
    3 9
    2 3
    2 9

    输出#1

    2 1
  • 输入#2

    3
    1 5
    2 6
    6 20

    输出#2

    -1 -1

说明/提示

In the first example the following pairs are considered correct:

  • (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
  • (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
  • (5, 2), (2, 5) — match exactly.

在第一个示例中,以下数对被认为是正确的:

  • (2, 1), (3, 1), (4, 1), (5, 1) — 完全不接触边界;
  • (3, 2), (4, 2), (3, 5), (4, 5) — 接触一条边界;
  • (5, 2), (2, 5) — 完全匹配。

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

首页