CF1619E.MEX and Increments

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Dmitry has an array of nn non-negative integers a1,a2,…,ana_1, a_2, \dots, a_n.

In one operation, Dmitry can choose any index jj (1≤j≤n1 \le j \le n) and increase the value of the element aja_j by 11. He can choose the same index jj multiple times.

For each ii from 00 to nn, determine whether Dmitry can make the MEX\mathrm{MEX} of the array equal to exactly ii. If it is possible, then determine the minimum number of operations to do it.

The MEX\mathrm{MEX} of the array is equal to the minimum non-negative integer that is not in the array. For example, the MEX\mathrm{MEX} of the array [3,1,0][3, 1, 0] is equal to 22, and the array [3,3,1,4][3, 3, 1, 4] is equal to 00.

德米特里有一个长度为 nn 的非负整数数组 a1,a2,…,ana_1, a_2, \dots, a_n。

在一次操作中,德米特里可以任选一个下标 jj(1≤j≤n1 \le j \le n),并将元素 aja_j 的值增加 11。他可以多次选择同一个下标 jj。

对每个从 00 到 nn 的整数 ii,判断德米特里是否能通过若干次操作使得该数组的 MEX\mathrm{MEX} 恰好等于 ii;若可以,则求出实现该目标所需的最少操作次数。

数组的 MEX\mathrm{MEX} 定义为不在该数组中的最小非负整数。例如,数组 [3,1,0][3, 1, 0] 的 MEX\mathrm{MEX} 为 22,而数组 [3,3,1,4][3, 3, 1, 4] 的 MEX\mathrm{MEX} 为 00。

输入格式

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

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 length of the array aa.

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

It is guaranteed that the sum of the values nn over all test cases in the test does not exceed 2⋅1052\cdot10^5.

输入数据的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示输入中测试用例的数量。

随后是各测试用例的描述。

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

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

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

输出格式

For each test case, output n+1n + 1 integer — ii-th number is equal to the minimum number of operations for which you can make the array MEX\mathrm{MEX} equal to ii (0≤i≤n0 \le i \le n), or -1 if this cannot be done.

对于每个测试用例,输出 n+1n + 1 个整数——其中第 ii 个数等于使数组的 MEX\mathrm{MEX} 等于 ii(0≤i≤n0 \le i \le n)所需的最少操作次数;若无法实现,则输出 −1-1。

输入输出样例

  • 输入#1

    5
    3
    0 1 3
    7
    0 1 2 3 4 3 2
    4
    3 0 0 0
    7
    4 6 2 3 5 0 5
    5
    4 0 1 0 4

    输出#1

    1 1 0 -1 
    1 1 2 2 1 0 2 6 
    3 0 1 4 3 
    1 0 -1 -1 -1 -1 -1 -1 
    2 1 0 2 -1 -1

说明/提示

In the first set of example inputs, n=3n=3:

  • to get MEX=0\mathrm{MEX}=0, it is enough to perform one increment: a1a_1++;
  • to get MEX=1\mathrm{MEX}=1, it is enough to perform one increment: a2a_2++;
  • MEX=2\mathrm{MEX}=2 for a given array, so there is no need to perform increments;
  • it is impossible to get MEX=3\mathrm{MEX}=3 by performing increments.

在第一组示例输入中,n=3n=3:

  • 要得到 MEX=0\mathrm{MEX}=0,只需执行一次自增操作:a1a_1++;
  • 要得到 MEX=1\mathrm{MEX}=1,只需执行一次自增操作:a2a_2++;
  • 给定数组的 MEX=2\mathrm{MEX}=2,因此无需执行任何自增操作;
  • 仅通过执行自增操作无法得到 MEX=3\mathrm{MEX}=3。

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

首页