第十九篇英文翻译
出处:https://acs.jxnu.edu.cn/contest/24/board/challenge/B
Fun with Even Subarrays
描述:
You are given an array
- Select some subarray from
a ">a of even size2 k ">2k that begins at positionl ">l (1 ≤ l ≤ l + 2 ⋅ k − 1 ≤ n ">1≤l≤l+2?k?1≤n1≤l≤l+2?k?1≤n,k ≥ 1 ">k≥1k≥1) and for eachi ">i between0 ">0 andk − 1 ">k?1 (inclusive), assign the value ">al+k+ial+k+i toa l + k + i ">al+ial+i.a l + i a ">2 k ">l ">1 ≤ l ≤ l + 2 ⋅ k − 1 ≤ n ">k ≥ 1 ">i ">0 ">k − 1 "> ">a l + k + i ">在数组中从下标l开始,选择偶数大小的子数组,且对于i从1到k-1,将a(l+k+i)的值赋给a(l+i);a l + i
For example, if
Find the minimum number of operations (possibly zero) needed to make all the elements of the array equal.
例如,如果a=[2,1,3,4,5,3],则选择l=1和k=2,应用此操作,数组将成为a=[3,4,3,4,5,3]。
找到使数组的所有元素相等所需的最小操作数(可能为零)。
输入:
The input consists of multiple test cases. The first line contains a single integer
The first line of each test case contains an integer
The second line of each test case consists of
It is guaranteed that the sum of
输入由多个测试用例组成。第一行包含一个整数t(1≤T≤2.?104)-测试用例的数量。测试用例的描述如下。
每个测试用例的第一行包含一个整数n(1)≤N≤2.?105)-数组的长度。
每个测试用例的第二行由n个整数a1、a2、…、an(1)组成≤人工智能≤n) -数组a的元素。
保证所有测试用例中n的总和不超过2?105
输出:
Print
打印t行,每行包含对应测试用例的答案——使数组中的所有元素与给定操作相等所需的最小操作数。
样例输入:
5 3 1 1 1 2 2 1 5 4 4 4 2 4 4 4 2 1 3 1 1
样例输出:
0 1 1 2 0
注释:
In the first test, all elements are equal, therefore no operations are needed.
In the second test, you can apply one operation with
In the third test, you can apply one operation with
In the fourth test, you can apply one operation with
In the fifth test, there is only one element, therefore no operations are needed.
注释:
在第一次测试中,所有元素都是相等的,因此不需要操作。
在第二个测试中,您可以应用一个k=1和l=1的操作,设置a1:=a2,数组将通过一个操作变成[1,1]。
在第三个测试中,可以应用一个k=1和l=4的操作,设置a4:=a5,数组变成[4,4,4,4]。
在第四个测试中,您可以应用一个k=1和l=3的操作,设置a3:=a4,数组变为[4,2,3,3],然后您可以应用另一个k=2和l=1的操作,设置a1:=a3,a2:=a4,数组变为[3,3,3,3]。
在第五个测试中,只有一个元素,因此不需要操作。