C. Dora and Search

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

A permutation of length n is an array consisting of n distinct integers from 1 to n in any order. For example, 2,3,1,5,4 is a permutation, but 1,2,2 is not a permutation (2 occurs twice in the array) and 1,3,4 is also not a permutation (n=3, but 4 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 t (1≤t≤104) --- the number of test cases. Description of the test cases follows.

For each test case, the first line contains one integer n (1≤n≤2⋅105) --- the length of permutation.

The second line contains n distinct integers a1,a2,...,an (1≤ai≤n) --- the elements of permutation.

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

Output

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

Otherwise, output two indexes l,r such that al,al+1,...,ar satisfies all conditions.

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

Example

Input

Copy

复制代码

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

Copy

复制代码
-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 satisfies all the conditions, because max(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 also satisfies all the conditions described.

解题说明:此题是一道模拟题,找出一对下标,使得对应数字符合要求。可以采用遍历算法,先假设l和r分别为数列头和数列尾,然后逐一判断,确保al和ar都不属于数列最大值和最小值。

cpp 复制代码
#include <stdio.h>

int a[200006];

int main(void) 
{
    int t;
    scanf("%d", &t);

    while (t--) 
    {
        int n;
        scanf("%d", &n);
  
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
        }
        int l = 1, r = n;
        int smallest = 1;
        int largest = n;

        while (l < r) 
        {
            int flag = 1;

            if (a[l - 1] <= smallest)
            {
                l++;
                smallest++;
                flag = 0;
            }
            if (a[r - 1] <= smallest) 
            {
                r--;
                smallest++;
                flag = 0;
            }
            if (a[l - 1] >= largest)
            {
                l++;
                largest--;
                flag = 0;
            }
            if (a[r - 1] >= largest) 
            {
                r--;
                largest--;
                flag = 0;
            }
            if (flag)
            {
                break;
            }
        }

        if (r - l <= 1)
        {
            printf("-1\n");
        }
        else
        {
            printf("%d %d\n", l, r);
        }
    }

    return 0;
}
相关推荐
Cc.Y3 小时前
Java零基础入门:字符串深度掌握——从基础API到StringBuilder性能优化
java·开发语言·性能优化
java资料站7 小时前
十一、评估测试
开发语言·人工智能·python
左手の明天7 小时前
SLIP 协议封装与解析详解:原理、C 代码与实战案例
linux·c语言·开发语言·c++
海上小飞龙8 小时前
【KMP算法-下篇】同一道题:Java 库函数 2600 微秒,手写 KMP 16 微秒
java·开发语言·算法
朝朝辞暮i8 小时前
C++ 第 12 课:局部变量、作用域、变量生命周期
开发语言·c++·算法
狗凯之家源码网8 小时前
淘客口令落地页生成器 PHP 版深度评测
开发语言·php
画绛集美术8 小时前
本地化部署LLM用于美术史问答:一间美术教室的实践记录
开发语言·php
八解毒剂9 小时前
【计组】中央处理器CPU
java·开发语言·计算机组成原理
小灰灰搞电子9 小时前
C语言 <ctype.h> 头文件详解
c语言·ctype.h
FakeOccupational9 小时前
【电路笔记 信号】DBPSK 波形查找表+脉冲成形(升余弦+根升余弦滤波)
开发语言·笔记