#P1376. Make Max
Make Max
Make Max
题目描述
You are given a sequence of positive integers . You can apply the following operation to the sequence: • Select a subarray where not all elements are identical (i.e., there exist two integers such that ), and then change every element in this subarray to . Determine the maximum number of such operations that can be performed.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases . Description of the test cases follows. The first line of each test case contains an integer ). The second line of each test case contains n integers . The sum of n over all test cases does not exceed .
输出格式
For each test case, print the maximum number of operations that can be performed.
样例 #1
样例输入 #1
4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3
样例输出 #1
1
0
3
3
提示
In the first test case, an optimal sequence of operations is:
- Select and apply the operation, so that a becomes .
In the second test case, no operation can be performed. In the fourth test case, an optimal sequence of operations is:
- Select and apply the operation, so that a becomes .
- Select and apply the operation, so that a becomes .
- Select and apply the operation, so that a becomes .