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 v′v′. 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,…,ana1,a2,…,an. 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,…,ajai,ai+1,…,aj for some 1≤i≤j≤n1≤i≤j≤n.

Input

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

The first line contains single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the corresponding values of the array aa.

It's guaranteed that the total length of all arrays in one test doesn't exceed 2⋅1052⋅105.

Output

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.

Example
input

Copy
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
output

Copy
-1
6
3
2
Note

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,a6a4,a5,a6 is the shortest dominated subarray.

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

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int n,a[maxn],pre[maxn];
int main() {
int t;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
int ans=0x3f3f3f3f;
for(int i=; i<=n; i++) pre[i]=-;
for(int i=; i<=n; i++) {
scanf("%d",&a[i]);//先输入
if(pre[a[i]]!=-)//判断之前有没有出现过
ans=min(ans,i-pre[a[i]]+);//如果出现过,取到上一个点的距离并取最小
pre[a[i]]=i;//标记此时点的距离
}
printf("%d\n",ans==0x3f3f3f3f?-:ans);
}
}
//计算每两个相同元素的距离对ans 取min

Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

  2. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  4. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  5. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

    E. The Contest A team of three programmers is going to play a contest. The contest consists of

  6. Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心

    D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of

  7. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题

    B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...

  8. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  9. Educational Codeforces Round 76 (Rated for Div. 2) D题

    题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...

随机推荐

  1. UVA750回溯法典例-八皇后

    文章代码选自UVA750-8 Queens Chess Problem的部分代码 vj题目链接:https://vjudge.net/problem/UVA-750 由于UVA中要求按照字典序输出,下 ...

  2. luogu P1736 创意吃鱼法

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...

  3. 使用Office365账号配置SMTP中继服务器

    · 如何将企业中的多功能设备(打印机.扫描仪等 )或应用程序设置为使用 Office 365 发送电子邮件,微软给出了3种方法: SMTP 客户端提交 直接发送 SMTP 中继 以上3种方式的介绍,大 ...

  4. LeetCode 938. 二叉搜索树的范围和

    题目链接:https://leetcode-cn.com/problems/range-sum-of-bst/ 给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和. 二叉搜 ...

  5. kindle怎么导入电子书

    参考网址:https://jingyan.baidu.com/article/59a015e342a165f795886545.html

  6. SpringMVC简单小结

    一.MVC的的大概解释: MVC的核心思想是业务数据抽取和业务数据呈现相分离. MVC:M(Model)+V(View)+C(Controller) M(模型层):业务数据的信息表示,通常是业务实体 ...

  7. 1级搭建类103-Oracle 12c 单实例 FS(12.2.0.1+RHEL 7)公开

    项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...

  8. linux 配置compoer

    配置默认php 删除 rm -f /usr/bin/php 改到php7.3版本的composer /bin/php /usr/bin/php 多版本支持 配置php7专用composer70 cd ...

  9. CTF入门 |“男神”背后的隐写术

    刚刚开始学CTF,记录一下做的第一道隐写题 ~ 附件下载 题目背景(我自己瞎编的): Luyu是CPPU的校草,一直以来他的写真照被各届校友广泛流传,最近江湖上流传着拿到这些照片就能知道Luyu的QQ ...

  10. [Arc083D/At3535] Restoring Road Network - 最短路,结论

    [Arc083D/At3535] 有 \(N\) 个城市,城市与城市之间用长度为整数的无向道路连接. 现有一考古学家找到了一张 \(N×N\) 的表 \(A\) ,这张表代表了这 \(N\) 座城市两 ...