CF1931C.Make Equal Again

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have an array aa of nn integers.

You can no more than once apply the following operation: select three integers ii, jj, xx (1≤i≤j≤n1 \le i \le j \le n) and assign all elements of the array with indexes from ii to jj the value xx. The price of this operation depends on the selected indices and is equal to (j−i+1)(j - i + 1) burles.

For example, the array is equal to [1,2,3,4,5,1][1, 2, 3, 4, 5, 1]. If we choose i=2,j=4,x=8i = 2, j = 4, x = 8, then after applying this operation, the array will be equal to [1,8,8,8,5,1][1, 8, 8, 8, 5, 1].

What is the least amount of burles you need to spend to make all the elements of the array equal?

你有一个包含 nn 个整数的数组 aa。

你最多可以执行一次如下操作:选择三个整数 ii、jj、xx(满足 1≤i≤j≤n1 \le i \le j \le n),并将数组中下标从 ii 到 jj 的所有元素赋值为 xx。该操作的代价取决于所选下标,其值为 (j−i+1)(j - i + 1) 卢布。

例如,数组为 [1,2,3,4,5,1][1, 2, 3, 4, 5, 1]。若我们选择 i=2i = 2、j=4j = 4、x=8x = 8,则执行该操作后,数组将变为 [1,8,8,8,5,1][1, 8, 8, 8, 5, 1]。

为使数组中所有元素相等,你至少需要花费多少卢布?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of input test cases. The descriptions of the test cases follow.

The first line of the description of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10 ^ 5) — the size of the array.

The second line of the description of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n) — array elements.

It is guaranteed that the sum of nn for all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入测试用例的数量。随后是各测试用例的描述。

每个测试用例的描述的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10 ^ 5)—— 数组的大小。

每个测试用例的描述的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)—— 数组元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output one integer — the minimum number of burles that will have to be spent to make all the elements of the array equal. It can be shown that this can always be done.

对于每个测试用例,输出一个整数——使数组所有元素相等所需花费的 burles 的最小数量。可以证明,这总是可行的。

输入输出样例

  • 输入#1

    8
    6
    1 2 3 4 5 1
    7
    1 1 1 1 1 1 1
    8
    8 8 8 1 2 8 8 8
    1
    1
    2
    1 2
    3
    1 2 3
    7
    4 3 2 7 1 1 3
    9
    9 9 2 9 2 5 5 5 3

    输出#1

    4
    0
    2
    0
    1
    2
    6
    7

输入解题思路,AI测评打分。不知道怎么写?

首页