아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Adjacent Pairs

시간 제한3초메모리 제한1024 MB

요약
인접한 원소가 같은 경우가 없는 배열이 주어질 때, 인접한 원소가 같지 않으면서 정확히 두 가지 값만 남도록 최소 개수의 위치를 바꾸는 문제이다.
난이도

보통10점 중 6점

유형
그리디, 구현, 수학
정답자
아직 제출이 없습니다

문제

Let's call an array b_1,b_2,…,b_mb\_1, b\_2, \dots , b\_m good, if b_i≠b_i+1b\_i ≠ b\_{i+1} for any ii with 1≤i≤m−11 ≤ i ≤ m - 1.

You are given a good array of nn positive integers a_1,a_2,a_3,…,a_na\_1, a\_2 , a\_3 , \dots , a\_n.

You can perform the following operations on this array:

Choose any index ii (1≤i≤n1 ≤ i ≤ n) and a number xx (1≤x≤1091 ≤ x ≤ 10^9). Then, set a_ia\_i to xx. 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 tt (1≤t≤1051 ≤ t ≤ 10^5), the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 ≤ n ≤ 2 ⋅ 10^5) - the length of the array.

The second line of each test case contains nn integers a_1,a_2,…,a_na\_1 , a\_2 , \dots , a\_n (1≤a_i≤n1 ≤ a\_i ≤ n) - elements of the array. It's guaranteed that a_i≠a_i+1a\_i ≠ a\_{i+1} for 1≤i≤n−11 ≤ i ≤ n - 1 (that is, the array is good).

It is guaranteed that the sum of n over all test cases does not exceed 2⋅1052 ⋅ 10^5.

출력

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.

힌트

In the first test case, one of the optimal sequences of operations is:

(4,5,2,4,5)→(2,5,2,4,5)→(2,5,2,4,2)→(2,5,2,5,2)(4, 5, 2, 4, 5) → (2, 5, 2, 4, 5) → (2, 5, 2, 4, 2) → (2, 5, 2, 5, 2).

In the second test case, the array already contains only two distinct values, so the answer is 00.

예제1

  1. 예제 1

    입력
    2
    5
    4 5 2 4 5
    2
    1 2
    
    예상 출력
    3
    0