311313: CF1969E. Unique Array

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Unique Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given an integer array $a$ of length $n$. A subarray of $a$ is one of its contiguous subsequences (i. e. an array $[a_l, a_{l+1}, \dots, a_r]$ for some integers $l$ and $r$ such that $1 \le l < r \le n$). Let's call a subarray unique if there is an integer that occurs exactly once in the subarray.

You can perform the following operation any number of times (possibly zero): choose an element of the array and replace it with any integer.

Your task is to calculate the minimum number of aforementioned operation in order for all the subarrays of the array $a$ to be unique.

Input

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$).

Additional constraint on the input: the sum of $n$ over all test cases doesn't exceed $3 \cdot 10^5$.

Output

For each test case, print a single integer — the minimum number of aforementioned operation in order for all the subarrays of the array $a$ to be unique.

ExampleInput
4
3
2 1 2
4
4 4 4 4
5
3 1 2 1 2
5
1 3 2 1 2
Output
0
2
1
0
Note

In the second test case, you can replace the $1$-st and the $3$-rd element, for example, like this: $[3, 4, 1, 4]$.

In the third test case, you can replace the $4$-th element, for example, like this: $[3, 1, 2, 3, 2]$.

Output

题目大意:
给定一个长度为n的整数数组a。a的一个子数组是它的一个连续子序列(即对于某些整数l和r,满足1≤l
输入数据格式:
第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。
每个测试用例的第一行包含一个整数n(1≤n≤3×10^5)。
第二行包含n个整数a_1, a_2, ..., a_n(1≤a_i≤n)。
输入数据的附加限制:所有测试用例的n之和不超过3×10^5。

输出数据格式:
对于每个测试用例,打印一个整数——使数组a的所有子数组都成为“unique”所需的最小操作次数。

示例:
输入:
4
3
2 1 2
4
4 4 4 4
5
3 1 2 1 2
5
1 3 2 1 2

输出:
0
2
1
0

注意:
在第二个测试用例中,你可以替换第1个和第3个元素,例如,像这样:[3, 4, 1, 4]。
在第三个测试用例中,你可以替换第4个元素,例如,像这样:[3, 1, 2, 3, 2]。题目大意: 给定一个长度为n的整数数组a。a的一个子数组是它的一个连续子序列(即对于某些整数l和r,满足1≤l

加入题单

上一题 下一题 算法标签: