CF2160B.Distinct Elements
普及-
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array c, let f(c) be the number of distinct elements in c. For example, f([1,2,2])=2 because there are two distinct elements in [1,2,2]: 1 and 2. Also, define c[i,j] as the subarray∗ of c bounded by positions i and j (that is, the array [ci,ci+1,…,cj]).
There is an array a of size n. An array b of n elements is constructed such that bi=f(a[1,i])+f(a[2,i])+…+f(a[i,i]). You are given the array b. Find any possible a with elements 1≤ai≤n. It is guaranteed that at least one possible a exists.
∗An array x is a subarray of an array y if x can be obtained from y by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
给定一个数组 c,令 f(c) 表示 c 中不同元素的个数。例如,f([1,2,2])=2,因为 [1,2,2] 中有两个不同的元素:1 和 2。此外,定义 c[i,j] 为数组 c 的一个子数组∗,其范围由位置 i 和 j 界定(即数组 [ci,ci+1,…,cj])。
现有一个长度为 n 的数组 a。据此构造一个长度为 n 的数组 b,使得对每个 i,有
bi=f(a[1,i])+f(a[2,i])+…+f(a[i,i]).
你将被给定数组 b。请找出任意一个满足条件的数组 a,其中每个元素满足 1≤ai≤n。题目保证至少存在一个合法的 a。
∗ 若数组 x 可通过从数组 y 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 x 是 y 的一个子数组。
输入格式
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≤105) – the number of elements in a and b.
The second line of each test case contains n integers b1,b2,…,bn (1≤bi≤1018).
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)——表示数组 a 和 b 的元素个数。
每个测试用例的第二行包含 n 个整数 b1,b2,…,bn(1≤bi≤1018)。
保证所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, print any possible a on a new line. The array a should satisfy 1≤ai≤n.
For every test case, it is guaranteed at least one a that satisfies the conditions exists.
对于每个测试用例,在一行中输出任意一个满足条件的 a。数组 a 应满足 1≤ai≤n。
对于每个测试用例,保证至少存在一个满足条件的 a。
输入输出样例
输入#1
4 3 1 3 6 3 1 3 5 3 1 3 4 4 1 2 3 7
输出#1
1 3 2 2 3 2 3 2 2 4 4 4 1
说明/提示
Let's verify our output for the second test case is correct:
- b1=f([2])=1
- b2=f([2,3])+f([3])=2+1=3
- b3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5
我们来验证第二个测试用例的输出是否正确:
- b1=f([2])=1
- b2=f([2,3])+f([3])=2+1=3
- b3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5
输入解题思路,AI测评打分。不知道怎么写?