CF1656A.Good Pairs

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n of positive integers. A good pair is a pair of indices (i,j)(i, j) with 1≤i,j≤n1 \leq i, j \leq n such that, for all 1≤k≤n1 \leq k \leq n, the following equality holds:

|a\_i - a\_k| + |a\_k - a\_j| = |a\_i - a\_j|, $$ where $|x|$ denotes the absolute value of $x$. Find a good pair. Note that $i$ can be equal to $j$. 给你一个由正整数组成的数组 $a_1, a_2, \ldots, a_n$。一个“好对”是指满足 $1 \leq i, j \leq n$ 的下标对 $(i, j)$,使得对所有 $1 \leq k \leq n$,以下等式成立: $$ |a\_i - a\_k| + |a\_k - a\_j| = |a\_i - a\_j|, $$ 其中 $|x|$ 表示 $x$ 的绝对值。 请找出一个好对。注意,$i$ 可以等于 $j$。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤1051 \leq n \leq 10^5) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) where aia_i is the ii-th element of the array.

The sum of nn for all test cases is at most 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9),其中 aia_i 表示数组的第 ii 个元素。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print a single line with two space-separated indices ii and jj which form a good pair of the array. The case i=ji=j is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.

对于每个测试用例,输出一行,包含两个以空格分隔的下标 ii 和 jj,它们构成该数组的一个“好”数对。允许 i=ji=j。可以证明这样的数对一定存在。如果存在多个“好”数对,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    3
    5 2 7
    5
    1 4 2 2 3
    1
    2

    输出#1

    2 3
    1 2
    1 1

说明/提示

In the first case, for i=2i = 2 and j=3j = 3 the equality holds true for all kk:

  • k=1k = 1: ∣a2−a1∣+∣a1−a3∣=∣2−5∣+∣5−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_1| + |a_1 - a_3| = |2 - 5| + |5 - 7| = 5 = |2 - 7| = |a_2-a_3|,
  • k=2k = 2: ∣a2−a2∣+∣a2−a3∣=∣2−2∣+∣2−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_2| + |a_2 - a_3| = |2 - 2| + |2 - 7| = 5 = |2 - 7| = |a_2-a_3|,
  • k=3k = 3: ∣a2−a3∣+∣a3−a3∣=∣2−7∣+∣7−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_3| + |a_3 - a_3| = |2 - 7| + |7 - 7| = 5 = |2 - 7| = |a_2-a_3|.

在第一种情况下,当 i=2i = 2 且 j=3j = 3 时,该等式对所有 kk 均成立:

  • k=1k = 1:∣a2−a1∣+∣a1−a3∣=∣2−5∣+∣5−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_1| + |a_1 - a_3| = |2 - 5| + |5 - 7| = 5 = |2 - 7| = |a_2-a_3|,
  • k=2k = 2:∣a2−a2∣+∣a2−a3∣=∣2−2∣+∣2−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_2| + |a_2 - a_3| = |2 - 2| + |2 - 7| = 5 = |2 - 7| = |a_2-a_3|,
  • k=3k = 3:∣a2−a3∣+∣a3−a3∣=∣2−7∣+∣7−7∣=5=∣2−7∣=∣a2−a3∣|a_2 - a_3| + |a_3 - a_3| = |2 - 7| + |7 - 7| = 5 = |2 - 7| = |a_2-a_3|。

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

首页