CF1714B Remove Prefix

题目描述

Polycarp是由一些长度为n的a整数序列组成的(1≤ai≤n)。只有当序列由不同的数字(即不同的数字)组成时,它才能使Polycarp高兴。 为了使他的序列像这样,Polycarp将进行一些移动(可能为零)。 在一个动作中,他可以: **删除**序列的**第一个(最左侧)元素。** 例如,在一次移动中,序列[3,1,4,3],将产生由不同数字组成的序列[1,4.3]。 确定他需要移动的最小次数,以便在剩余序列中所有元素都不同。**换句话说,在删除序列中的所有值后,查找给定序列的最小前缀的长度**。

输入格式

第一行输入t(1 $\le t \le 10^4$)——测试组数 每个测试输入两行 第一行输入n(1 $\le n \le 2·10^5$)——序列的长度 第二行输入长度为n的a数组$a_1,a_2,…,a_n$(1$ \le a_i \le n$)——序列内容 保证$n$不超过$2·10^5$.

输出格式

一行一个当前测试数据变成Polycarp高兴的序列所需的最小步数

说明/提示

The following are the sequences that will remain after the removal of prefixes: - $ [1, 4, 3] $ ; - $ [1] $ ; - $ [1] $ ; - $ [6, 5, 4, 3, 2, 1] $ ; - $ [2, 1] $ . It is easy to see that all the remaining sequences contain only distinct elements. In each test case, the shortest matching prefix was removed.