CF2137E.Mexification
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of size n and an integer k. You do the following procedure k times:
- For each element ai, you set ai to mex∗(a1,a2,…,ai−1,ai+1,ai+2,…,an). In other words, you set ai to the mex of all other elements in the array. This is done for all elements in the array at the same time.
Please find the sum of elements in the array after all k operations.
∗The minimum excluded (MEX) of a collection of integers d1,d2,…,dk is defined as the smallest non-negative integer x which does not occur in the collection d.
给你一个大小为 n 的数组 a 和一个整数 k。你执行以下操作 k 次:
- 对于每个元素 ai,将其设置为 mex∗(a1,a2,…,ai−1,ai+1,ai+2,…,an)。换言之,将 ai 设置为数组中其余所有元素的 mex。该操作对数组中所有元素同时进行。
请计算经过全部 k 次操作后,数组中所有元素的和。
∗ 一组整数 d1,d2,…,dk 的最小未出现值(MEX) 定义为未在该集合 d 中出现的最小非负整数 x。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line contains two integers n and k (2≤n≤2⋅105,1≤k≤109) – the number of elements in a and the number of operations done.
The second line contains n integers a1,a2,…,an (0≤ai≤n).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
第一行包含两个整数 n 和 k(2≤n≤2⋅105, 1≤k≤109)——分别表示数组 a 的元素个数以及执行的操作次数。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output the sum of elements after all k operations on a new line.
对于每个测试用例,在一行中输出执行所有 k 次操作后的元素之和。
输入输出样例
输入#1
5 3 3 0 2 1 2 4 0 2 4 1 0 0 1 1 8 7 6 6 2 4 3 0 1 8 2 2 0 0
输出#1
3 1 8 25 0
说明/提示
In the first test case, we performed the operation on the array [0,2,1] three times. Let's compute the result after the first time:
- The first element becomes MEX(2,1)=0
- The second element becomes MEX(0,1)=2
- The third element becomes MEX(0,2)=1
So, after the first operation, [0,2,1] becomes [0,2,1] again. It can be shown that the array will not change no matter how many times we perform the operation, so the final array after three operations is still [0,2,1]. The sum is 0+2+1=3.
In the third test case, the array becomes [2,2,2,2].
在第一个测试用例中,我们对数组 [0,2,1] 执行了三次操作。我们来计算第一次操作后的结果:
- 第一个元素变为 MEX(2,1)=0;
- 第二个元素变为 MEX(0,1)=2;
- 第三个元素变为 MEX(0,2)=1。
因此,第一次操作后,[0,2,1] 仍为 [0,2,1]。可以证明,无论执行多少次该操作,数组均不会发生变化,故经过三次操作后的最终数组仍是 [0,2,1]。其元素和为 0+2+1=3。
在第三个测试用例中,数组变为 [2,2,2,2]。
输入解题思路,AI测评打分。不知道怎么写?