#d2610. 数组操作
数组操作
Array Operation
Problem Description
You are given an array of elements. You may perform the following operation any number of times:
From an even-sized subarray of size starting at position (, ), for each from to inclusive, assign the value to .
For example, if and you choose and , then after applying this operation the array becomes .
Find the minimum number of operations (possibly zero) required to make all elements of the array equal.
Input Format
The input consists of multiple test cases. The first line contains an integer (), the number of test cases.
Each test case consists of integers:
The first integer () is the length of the array.
The following integers () are the elements of the array.
Output Format
Output lines, each containing one integer: the minimum number of operations required to make all elements equal using the given operation.
Sample Input
5
3 1 1 1
2 2 1
5 4 4 4 2 4
4 4 2 1 3
1 1
Sample Output
0
1
1
2
0
Constraints
The sum of over all test cases does not exceed .
Hint
In the first test, all elements are already equal, so no operation is needed.
In the second test, you can apply one operation with , setting , turning the array into in operation.
In the third test, you can apply one operation with , setting , turning the array into .
In the fourth test, you can apply one operation with , setting , turning the array into ; then you can apply another operation with , setting , turning the array into .
In the fifth test, there is only one element, so no operation is needed.