2160B.md (1976B)
1 Source: https://codeforces.com/problemset/problem/2160/B 2 3 B. Distinct Elements 4 5 time limit per test 6 7 1.5 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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$^{\text{∗}}$ of $c$ bounded by positions $i$ and $j$ (that is, the array $[c_i,c_{i+1},\ldots,c_j]$). 22 23 There is an array $a$ of size $n$. An array $b$ of $n$ elements is constructed such that $b_i=f(a[1,i])+f(a[2,i])+\ldots+f(a[i,i])$. You are given the array $b$. Find any possible $a$ with elements $1 \leq a_i \leq n$. It is guaranteed that at least one possible $a$ exists. 24 25 $^{\text{∗}}$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. 26 27 Input 28 29 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 30 31 The first line of each test case contains an integer $n$ ($1 \leq n \leq 10^5$) – the number of elements in $a$ and $b$. 32 33 The second line of each test case contains $n$ integers $b_1,b_2,\ldots,b_n$ ($1 \leq b_i \leq 10^{18}$). 34 35 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 36 37 Output 38 39 For each test case, print any possible $a$ on a new line. The array $a$ should satisfy $1\leq a_i\leq n$. 40 41 For every test case, it is guaranteed at least one $a$ that satisfies the conditions exists. 42 43 Example 44 45 Input 46 47 ``` 48 4 49 50 3 51 52 1 3 6 53 54 3 55 56 1 3 5 57 58 3 59 60 1 3 4 61 62 4 63 64 1 2 3 7 65 ``` 66 67 Output 68 69 ``` 70 1 3 2 71 2 3 2 72 3 2 2 73 4 4 4 1 74 ``` 75 76 Note 77 78 Let's verify our output for the second test case is correct: 79 80 * $b_1=f([2])=1$ 81 * $b_2=f([2,3])+f([3])=2+1=3$ 82 * $b_3=f([2,3,2])+f([3,2])+f([2])=2+2+1=5$