CF2160B.Distinct Elements

普及-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an array cc, let f(c)f(c) be the number of distinct elements in cc. For example, f([1,2,2])=2f([1,2,2])=2 because there are two distinct elements in [1,2,2][1,2,2]: 11 and 22. Also, define c[i,j]c[i,j] as the subarray∗^{\text{∗}} of cc bounded by positions ii and jj (that is, the array [ci,ci+1,…,cj][c_i,c_{i+1},\ldots,c_j]).

There is an array aa of size nn. An array bb of nn elements is constructed such that bi=f(a[1,i])+f(a[2,i])+…+f(a[i,i])b_i=f(a[1,i])+f(a[2,i])+\ldots+f(a[i,i]). You are given the array bb. Find any possible aa with elements 1≤ai≤n1 \leq a_i \leq n. It is guaranteed that at least one possible aa exists.

∗^{\text{∗}}An array xx is a subarray of an array yy if xx can be obtained from yy by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

给定一个数组 cc,令 f(c)f(c) 表示 cc 中不同元素的个数。例如,f([1,2,2])=2f([1,2,2])=2,因为 [1,2,2][1,2,2] 中有两个不同的元素:11 和 22。此外,定义 c[i,j]c[i,j] 为数组 cc 的一个子数组∗^{\text{∗}},其范围由位置 ii 和 jj 界定(即数组 [ci,ci+1,…,cj][c_i,c_{i+1},\ldots,c_j])。

现有一个长度为 nn 的数组 aa。据此构造一个长度为 nn 的数组 bb,使得对每个 ii,有

bi=f(a[1,i])+f(a[2,i])+…+f(a[i,i]).b_i = f(a[1,i]) + f(a[2,i]) + \ldots + f(a[i,i]).

你将被给定数组 bb。请找出任意一个满足条件的数组 aa,其中每个元素满足 1≤ai≤n1 \leq a_i \leq n。题目保证至少存在一个合法的 aa。

∗^{\text{∗}} 若数组 xx 可通过从数组 yy 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 xx 是 yy 的一个子数组。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤1051 \leq n \leq 10^5) – the number of elements in aa and bb.

The second line of each test case contains nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n (1≤bi≤10181 \leq b_i \leq 10^{18}).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——表示数组 aa 和 bb 的元素个数。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\ldots,b_n(1≤bi≤10181 \leq b_i \leq 10^{18})。

保证所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, print any possible aa on a new line. The array aa should satisfy 1≤ai≤n1\leq a_i\leq n.

For every test case, it is guaranteed at least one aa that satisfies the conditions exists.

对于每个测试用例,在一行中输出任意一个满足条件的 aa。数组 aa 应满足 1≤ai≤n1\leq a_i\leq n。

对于每个测试用例,保证至少存在一个满足条件的 aa。

输入输出样例

  • 输入#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])=1b_1=f([2])=1
  • b2=f([2,3])+f([3])=2+1=3b_2=f([2,3])+f([3])=2+1=3
  • b3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5b_3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5

我们来验证第二个测试用例的输出是否正确:

  • b1=f([2])=1b_1=f([2])=1
  • b2=f([2,3])+f([3])=2+1=3b_2=f([2,3])+f([3])=2+1=3
  • b3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5b_3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5

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

首页