CF1433C.Dominant Piranha

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn piranhas with sizes a1,a2,…,ana_1, a_2, \ldots, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.

Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.

Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:

  • The piranha ii can eat the piranha i−1i-1 if the piranha i−1i-1 exists and ai−1<aia_{i - 1} \lt a_i.
  • The piranha ii can eat the piranha i+1i+1 if the piranha i+1i+1 exists and ai+1<aia_{i + 1} \lt a_i.

When the piranha ii eats some piranha, its size increases by one (aia_i becomes ai+1a_i + 1).

Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.

Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.

For example, if a=[5,3,4,4,5]a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:

  • The piranha eats the second piranha and aa becomes [5,5‾,4,5][5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
  • The piranha eats the third piranha and aa becomes [5,6‾,5][5, \underline{6}, 5].
  • The piranha eats the first piranha and aa becomes [7‾,5][\underline{7}, 5].
  • The piranha eats the second piranha and aa becomes [8‾][\underline{8}].

You have to answer tt independent test cases.

水族箱中有 nn 条食人鱼,其体型大小分别为 a1,a2,…,ana_1, a_2, \ldots, a_n。食人鱼从左到右依次编号,编号顺序即为其在水族箱中的位置顺序。

贝尔兰国立大学的科学家们希望判断水族箱中是否存在一条“主导食人鱼”。若某条食人鱼能够吃掉水族箱中其余所有食人鱼(当然不包括自身),则称其为主导食人鱼。其余食人鱼在此过程中将保持静止,仅该主导食人鱼主动捕食。

由于水族箱狭长,一条食人鱼每次只能吃掉与其相邻的一条食人鱼。它可进行任意多次(只要条件允许)这样的操作。更准确地说:

  • 食人鱼 ii 可以吃掉食人鱼 i−1i-1,当且仅当 i−1i-1 存在(即 i>1i > 1)且 ai−1<aia_{i - 1} \lt a_i;
  • 食人鱼 ii 可以吃掉食人鱼 i+1i+1,当且仅当 i+1i+1 存在(即 i<ni < n)且 ai+1<aia_{i + 1} \lt a_i。

当食人鱼 ii 吃掉某条食人鱼后,其体型增大 1(即 aia_i 变为 ai+1a_i + 1)。

你的任务是:在水族箱中找出任意一条主导食人鱼;若不存在,则判定为无解。

注意:你只需找出任意一条(恰好一条)主导食人鱼,无需找出所有可能的主导食人鱼。

例如,若 a=[5,3,4,4,5]a = [5, 3, 4, 4, 5],则第 3 条食人鱼可以成为主导食人鱼。考虑其一系列操作:

  • 该食人鱼吃掉第 2 条食人鱼,aa 变为 [5,5‾,4,5][5, \underline{5}, 4, 5](下划线标出的为候选食人鱼);
  • 该食人鱼吃掉第 3 条食人鱼,aa 变为 [5,6‾,5][5, \underline{6}, 5];
  • 该食人鱼吃掉第 1 条食人鱼,aa 变为 [7‾,5][\underline{7}, 5];
  • 该食人鱼吃掉第 2 条食人鱼,aa 变为 [8‾][\underline{8}]。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤2⋅1041 \le t \le 2 \cdot 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5) — the number of piranhas in the aquarium. The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the size of the ii-th piranha.

It is guaranteed that the sum of nn does not exceed 3⋅1053 \cdot 10^5 (∑n≤3⋅105\sum n \le 3 \cdot 10^5).

输入的第一行包含一个整数 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5),表示水族箱中食人鱼的数量。每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 条食人鱼的体型大小。

保证所有测试用例中 nn 的总和不超过 3⋅1053 \cdot 10^5(即 ∑n≤3⋅105\sum n \le 3 \cdot 10^5)。

输出格式

For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.

对于每个测试用例,输出答案:若水族箱中不存在主导食人鱼,则输出 -1;否则输出任意一个主导食人鱼的下标。若存在多个答案,可输出其中任意一个。

输入输出样例

  • 输入#1

    6
    5
    5 3 4 4 5
    3
    1 1 1
    5
    4 4 3 4 4
    5
    5 5 4 3 2
    3
    1 1 2
    5
    5 4 3 5 5

    输出#1

    3
    -1
    4
    3
    3
    1

说明/提示

The first test case of the example is described in the problem statement.

In the second test case of the example, there are no dominant piranhas in the aquarium.

In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4,4,5,4][4, 4, 5, 4], then it can eat any other piranha in the aquarium.

示例的第一个测试用例已在题目描述中说明。

示例的第二个测试用例中,水族箱中不存在优势食人鱼。

示例的第三个测试用例中,第四条食人鱼首先可以吃掉其左侧的食人鱼,此时水族箱变为 [4,4,5,4][4, 4, 5, 4],之后它可以吃掉水族箱中的任意其他食人鱼。

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

首页