CF2137D.Replace with Occurrences
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a, let f(x) be the number of occurrences of x in the array a. For example, when a=[1,2,3,1,4], then f(1)=2 and f(3)=1.
You have an array b of size n. Please determine if there is an array a of size n such that f(ai)=bi for all 1≤i≤n. If there is one, construct it.
给定一个数组 a,令 f(x) 表示 x 在数组 a 中出现的次数。例如,当 a=[1,2,3,1,4] 时,有 f(1)=2 且 f(3)=1。
你有一个长度为 n 的数组 b。请判断是否存在一个长度为 n 的数组 a,使得对所有 1≤i≤n 均满足 f(ai)=bi。若存在,请构造出这样的数组 a。
输入格式
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 of each test case contains an integer n (1≤n≤2⋅105).
The second line contains n integers b1,b2,…,bn (1≤bi≤n).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)。
第二行包含 n 个整数 b1,b2,…,bn(1≤bi≤n)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output −1 if there is no valid array a.
Otherwise, print the array a of n integers on a new line. The elements should satisfy 1≤ai≤n.
对于每个测试用例,若不存在合法的数组 a,则输出 −1。
否则,在新的一行中输出由 n 个整数组成的数组 a。其中各元素需满足 1≤ai≤n。
输入输出样例
输入#1
3 4 1 2 3 4 6 1 2 2 3 3 3 6 6 6 6 6 6 6
输出#1
-1 4 5 5 6 6 6 2 2 2 2 2 2
说明/提示
In the first test case, it can be shown that no array matches the requirement.
In the second test case, 4, 5, 6 appear 1,2,3 times respectively. Thus, the output array is correct as f(4),f(5),f(5),f(6),f(6),f(6) are 1,2,2,3,3,3 respectively.
在第一个测试用例中,可以证明不存在满足要求的数组。
在第二个测试用例中,4、5、6 分别出现 1、2、3 次。因此,输出数组是正确的,因为 f(4),f(5),f(5),f(6),f(6),f(6) 的值分别为 1,2,2,3,3,3。
输入解题思路,AI测评打分。不知道怎么写?