CF1257C.Dominated Subarray

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Let's call an array tt dominated by value vv in the next situation.

At first, array tt should have at least 22 elements. Now, let's calculate number of occurrences of each number numnum in tt and define it as occ(num)occ(num) . Then tt is dominated (by vv ) if (and only if) occ(v)>occ(v)occ(v) > occ(v') for any other number vv' . For example, arrays [1,2,3,4,5,2][1, 2, 3, 4, 5, 2] , [11,11][11, 11] and [3,2,3,2,3][3, 2, 3, 2, 3] are dominated (by 22 , 1111 and 33 respectevitely) but arrays [3][3] , [1,2][1, 2] and [3,3,2,2,1][3, 3, 2, 2, 1] are not.

Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.

You are given array a1,a2,,ana_1, a_2, \dots, a_n . Calculate its shortest dominated subarray or say that there are no such subarrays.

The subarray of aa is a contiguous part of the array aa , i. e. the array ai,ai+1,,aja_i, a_{i + 1}, \dots, a_j for some 1ijn1 \le i \le j \le n .

输入格式

The first line contains single integer TT ( 1T10001 \le T \le 1000 ) — the number of test cases. Each test case consists of two lines.

The first line contains single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of the array aa .

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ain1 \le a_i \le n ) — the corresponding values of the array aa .

It's guaranteed that the total length of all arrays in one test doesn't exceed 21052 \cdot 10^5 .

输出格式

Print TT integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or 1-1 if there are no such subarrays.

输入输出样例

  • 输入#1

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

    输出#1

    -1
    6
    3
    2
    

说明/提示

In the first test case, there are no subarrays of length at least 22 , so the answer is 1-1 .

In the second test case, the whole array is dominated (by 11 ) and it's the only dominated subarray.

In the third test case, the subarray a4,a5,a6a_4, a_5, a_6 is the shortest dominated subarray.

In the fourth test case, all subarrays of length more than one are dominated.

首页