Codeforces Round 782 (Div. 2)
D
Reverse Sort Sum
Codeforces
1900
原题
← CE →
翻译中…

Suppose you had an array $A$ of $n$ elements, each of which is $0$ or $1$.

翻译中…

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

翻译中…

Now consider the arrays $B_1, B_2,\ldots, B_n$ generated by $f(1,A), f(2,A),\ldots,f(n,A)$. Let $C$ be the array obtained by taking the element-wise sum of $B_1, B_2,\ldots, B_n$.

翻译中…

For example, let $A=[0,1,0,1]$. Then we have $B_1=[0,1,0,1]$, $B_2=[0,1,0,1]$, $B_3=[0,0,1,1]$, $B_4=[0,0,1,1]$. Then $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 $C$. Determine a binary array $A$ that would give $C$ when processed as above. It is guaranteed that an array $A$ exists for given $C$ in the input.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($0 \leq c_i \leq n$). It is guaranteed that a valid array $A$ exists for the given $C$.

翻译中…

The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single line containing $n$ integers $a_1, a_2, \ldots, a_n$ ($a_i$ is $0$ or $1$). If there are multiple answers, you may output any of them.

翻译中…

Note

翻译中…

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

翻译中…
  • $B_1=[\color{blue}{1},1,0,1]$;
  • $B_2=[\color{blue}{1},\color{blue}{1},0,1]$;
  • $B_3=[\color{blue}{0},\color{blue}{1},\color{blue}{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]$.

翻译中…

样例

Input #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
Output #1
1 1 0 1
0 1 1 0 0 0 1
0 0 0
0 0 0 1
1 0 1
InputCopy OutputCopy
题目信息
题号
1659D
时间限制
2 s
内存限制
256 MB
标签
构造
数据结构
贪心
模拟
数学
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。