Codeforces 1793C. Dora and Search

题目

链接:https://codeforces.com/problemset/problem/1793/C

time limit per test:1 second;memory limit per test:256 megabytes

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≤l≤r≤n) such that al≠min(al,al+1,…,ar)al≠min(al,al+1,…,ar), al≠max(al,al+1,…,ar)al≠max(al,al+1,…,ar) and ar≠min(al,al+1,…,ar)ar≠min(al,al+1,…,ar), ar≠max(al,al+1,…,ar)ar≠max(al,al+1,…,ar).

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.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — 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≤n≤2⋅105) — the length of permutation.

The second line contains nn distinct integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the elements of permutation.

It is guarented that the sum of nn over all test cases doesn't exceed 2⋅1052⋅105.

Output

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][al,al+1,…,ar] satisfies all conditions.

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

Example

Input

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

Output

-1
1 4
2 6
-1

Note

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)=1max(a1,a2,a3,a4)=4,min(a1,a2,a3,a4)=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 ,最小值变化,只能是加 1

 

代码

t=int(input())
for _ in range(t):
    n=int(input())
    perm=list(map(int,input().split()))
    # print(perm)
    # increasing_perm=sorted(perm)
    # decreasing_perm=sorted(perm,reverse=True)
    i,j=1,n
    ans=[]
    top = n
    bottom = 1
    while i

你可能感兴趣的:(python,constructive,two,pointers,data,structures)