CF1659D.Reverse Sort Sum

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Suppose you had an array AA of nn elements, each of which is 00 or 11.

Let us define a function f(k,A)f(k,A) which returns another array BB, the result of sorting the first kk elements of AA in non-decreasing order. For example, f(4,[0,1,1,0,0,1,0])=[0,0,1,1,0,1,0]f(4,[0,1,1,0,0,1,0]) = [0,0,1,1,0,1,0]. Note that the first 44 elements were sorted.

Now consider the arrays B1,B2,…,BnB_1, B_2,\ldots, B_n generated by f(1,A),f(2,A),…,f(n,A)f(1,A), f(2,A),\ldots,f(n,A). Let CC be the array obtained by taking the element-wise sum of B1,B2,…,BnB_1, B_2,\ldots, B_n.

For example, let A=[0,1,0,1]A=[0,1,0,1]. Then we have B1=[0,1,0,1]B_1=[0,1,0,1], B2=[0,1,0,1]B_2=[0,1,0,1], B3=[0,0,1,1]B_3=[0,0,1,1], B4=[0,0,1,1]B_4=[0,0,1,1]. Then C=B1+B2+B3+B4=[0,1,0,1]+[0,1,0,1]+[0,0,1,1]+[0,0,1,1]=[0,2,2,4]C=B_1+B_2+B_3+B_4=[0,1,0,1]+[0,1,0,1]+[0,0,1,1]+[0,0,1,1]=[0,2,2,4].

You are given CC. Determine a binary array AA that would give CC when processed as above. It is guaranteed that an array AA exists for given CC in the input.

假设你有一个长度为 nn 的数组 AA,其中每个元素均为 00 或 11。

我们定义一个函数 f(k,A)f(k,A),它返回另一个数组 BB,该数组是将 AA 的前 kk 个元素按非递减顺序排序后得到的结果。例如,f(4,[0,1,1,0,0,1,0])=[0,0,1,1,0,1,0]f(4,[0,1,1,0,0,1,0]) = [0,0,1,1,0,1,0]。注意,仅前 44 个元素被排序。

现在考虑由 f(1,A),f(2,A),…,f(n,A)f(1,A), f(2,A),\ldots,f(n,A) 生成的数组 B1,B2,…,BnB_1, B_2,\ldots, B_n。令 CC 为 B1,B2,…,BnB_1, B_2,\ldots, B_n 的逐元素和(即对每个位置 ii,C[i]=B1[i]+B2[i]+⋯+Bn[i]C[i] = B_1[i] + B_2[i] + \cdots + B_n[i])。

例如,设 A=[0,1,0,1]A=[0,1,0,1]。则有:
B1=[0,1,0,1]B_1=[0,1,0,1],
B2=[0,1,0,1]B_2=[0,1,0,1],
B3=[0,0,1,1]B_3=[0,0,1,1],
B4=[0,0,1,1]B_4=[0,0,1,1]。
于是 C=B1+B2+B3+B4=[0,1,0,1]+[0,1,0,1]+[0,0,1,1]+[0,0,1,1]=[0,2,2,4]C=B_1+B_2+B_3+B_4=[0,1,0,1]+[0,1,0,1]+[0,0,1,1]+[0,0,1,1]=[0,2,2,4]。

现给你数组 CC,请确定一个二进制数组 AA,使得按上述过程处理 AA 后恰好得到 CC。题目保证:对输入中给定的 CC,总存在满足条件的数组 AA。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

Each test case has two lines. The first line contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5).

The second line contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (0≤ci≤n0 \leq c_i \leq n). It is guaranteed that a valid array AA exists for the given CC.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。

每个测试用例包含两行。第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(0≤ci≤n0 \leq c_i \leq n)。保证对于给定的 CC,存在一个合法的数组 AA。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single line containing nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (aia_i is 00 or 11). If there are multiple answers, you may output any of them.

对于每个测试用例,输出一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(其中每个 aia_i 为 00 或 11)。如果存在多个答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

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

    输出#1

    1 1 0 1 
    0 1 1 0 0 0 1 
    0 0 0 
    0 0 0 1 
    1 0 1

说明/提示

Here's the explanation for the first test case. Given that A=[1,1,0,1]A=[1,1,0,1], we can construct each BiB_i:

  • B1=[1,1,0,1]B_1=[\color{blue}{1},1,0,1];
  • B2=[1,1,0,1]B_2=[\color{blue}{1},\color{blue}{1},0,1];
  • B3=[0,1,1,1]B_3=[\color{blue}{0},\color{blue}{1},\color{blue}{1},1];
  • B4=[0,1,1,1]B_4=[\color{blue}{0},\color{blue}{1},\color{blue}{1},\color{blue}{1}]

And then, we can sum up each column above to get C=[1+1+0+0,1+1+1+1,0+0+1+1,1+1+1+1]=[2,4,2,4]C=[1+1+0+0,1+1+1+1,0+0+1+1,1+1+1+1]=[2,4,2,4].

以下是第一个测试用例的解释。给定 A=[1,1,0,1]A=[1,1,0,1],我们可以构造每个 BiB_i:

  • B1=[1,1,0,1]B_1=[\color{blue}{1},1,0,1];
  • B2=[1,1,0,1]B_2=[\color{blue}{1},\color{blue}{1},0,1];
  • B3=[0,1,1,1]B_3=[\color{blue}{0},\color{blue}{1},\color{blue}{1},1];
  • B4=[0,1,1,1]B_4=[\color{blue}{0},\color{blue}{1},\color{blue}{1},\color{blue}{1}]

然后,我们将上述每列分别求和,得到 C=[1+1+0+0,1+1+1+1,0+0+1+1,1+1+1+1]=[2,4,2,4]C=[1+1+0+0,1+1+1+1,0+0+1+1,1+1+1+1]=[2,4,2,4]。

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

首页