CF1793C.Dora and Search

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

As you know, the girl Dora is always looking for something. This time she was given a permutation, and she wants to find such a subsegment of it that none of the elements at its ends is either the minimum or the maximum of the entire subsegment. More formally, you are asked to find the numbers ll and rr (1≤l≤r≤n)(1 \leq l \leq r \leq n) such that al≠min⁡(al,al+1,…,ar)a_l \neq \min(a_l, a_{l + 1}, \ldots, a_r), al≠max⁡(al,al+1,…,ar)a_l \neq \max(a_l, a_{l + 1}, \ldots, a_r) and ar≠min⁡(al,al+1,…,ar)a_r \neq \min(a_l, a_{l + 1}, \ldots, a_r), ar≠max⁡(al,al+1,…,ar)a_r \neq \max(a_l, a_{l + 1}, \ldots, a_r).

A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in any order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 occurs twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3, but 44 is present in the array).

Help Dora find such a subsegment, or tell her that such a subsegment does not exist.

众所周知,女孩朵拉总是在寻找某些东西。这一次,她得到了一个排列,她希望从中找到一个子段,使得该子段两端的元素均不等于该子段的最小值或最大值。更准确地说,你需要找出满足 1≤l≤r≤n1 \leq l \leq r \leq n 的整数 ll 和 rr,使得

al≠min⁡(al,al+1,…,ar),al≠max⁡(al,al+1,…,ar)a_l \neq \min(a_l, a_{l + 1}, \ldots, a_r), \quad a_l \neq \max(a_l, a_{l + 1}, \ldots, a_r)

且

ar≠min⁡(al,al+1,…,ar),ar≠max⁡(al,al+1,…,ar).a_r \neq \min(a_l, a_{l + 1}, \ldots, a_r), \quad a_r \neq \max(a_l, a_{l + 1}, \ldots, a_r).

长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列;而 [1,2,2][1,2,2] 不是排列(数字 22 在数组中出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n = 3,但数组中却出现了 44)。

请帮助朵拉找到这样一个子段;若不存在这样的子段,则告诉她不存在。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Description of the test cases follows.

For each test case, the first line contains one integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of permutation.

The second line contains nn distinct integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \leq a_i \leq n) — the elements of permutation.

It is guarented that the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

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

第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \leq a_i \leq n),表示该排列的元素。

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

输出格式

For each test case, output −1-1 if the desired subsegment does not exist.

Otherwise, output two indexes l,rl, r such that [al,al+1,…,ar][a_{l}, a_{l + 1}, \ldots, a_{r}] satisfies all conditions.

If there are several solutions, then output any of them.

对于每个测试用例,如果所要求的子段不存在,则输出 −1-1。

否则,输出两个下标 l,rl, r,使得子段 [al,al+1,…,ar][a_{l}, a_{l + 1}, \ldots, a_{r}] 满足所有条件。

如果有多个解,输出其中任意一个即可。

输入输出样例

  • 输入#1

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

    输出#1

    -1
    1 4
    2 6
    -1

说明/提示

In the first and fourth test cases, it can be shown that there are no desired subsegments.

In the second test case, the subsegment [1,4][1, 4] satisfies all the conditions, because max⁡(a1,a2,a3,a4)=4,min⁡(a1,a2,a3,a4)=1\max(a_1, a_2, a_3, a_4) = 4, \min(a_1, a_2, a_3, a_4) = 1, as we see, all the conditions are met.

In the third test case, the subsegment [2,6][2, 6] also satisfies all the conditions described.

在第一和第四个测试用例中,可以证明不存在满足要求的子区间。

在第二个测试用例中,子区间 [1,4][1, 4] 满足所有条件,因为 max⁡(a1,a2,a3,a4)=4, min⁡(a1,a2,a3,a4)=1\max(a_1, a_2, a_3, a_4) = 4,\ \min(a_1, a_2, a_3, a_4) = 1,如我们所见,所有条件均被满足。

在第三个测试用例中,子区间 [2,6][2, 6] 同样满足所述的所有条件。

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

首页