#P13781. [eJOI 2022] Adjacent Pairs
[eJOI 2022] Adjacent Pairs
题目描述
Let's call an array good, if for any with .
You are given a good array of positive integers .
You can perform the following operations on this array:
- Choose any index () and a number (). Then, set to . After this operation, the array has to remain good.
You want to perform several operations so that the resulting array will contain exactly two distinct values. Determine the smallest number of operations needed to achieve this goal.
输入格式
The first line of input contains the integer (), the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () - the length of the array.
The second line of each test case contains integers () - elements of the array. It's guaranteed that for (that is, the array is good).
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output a single integer - the smallest number of operations needed to achieve an array in which there are exactly two distinct values.
2
5
4 5 2 4 5
2
1 2
3
0
提示
Note
In the first test case, one of the optimal sequences of operations is:
$(4, 5, 2, 4, 5) \rightarrow (2, 5, 2, 4, 5) \rightarrow (2, 5, 2, 4, 2) \rightarrow (2, 5, 2, 5, 2)$.
In the second test case, the array already contains only two distinct values, so the answer is .
Scoring
- (20 points): The sum of over all test cases does not exceed
- (10 points): The sum of over all test cases does not exceed
- (25 points): The sum of over all test cases does not exceed
- (45 points): No additional constraints