2049C.md (2813B)
1 Source: https://codeforces.com/problemset/problem/2049/C 2 3 C. MEX Cycle 4 5 time limit per test 6 7 2 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 Evirir the dragon has many friends. They have 3 friends! That is one more than the average dragon. 22 23 You are given integers $n$, $x$, and $y$. There are $n$ dragons sitting in a circle. The dragons are numbered $1, 2, \ldots, n$. For each $i$ ($1 \le i \le n$), dragon $i$ is friends with dragon $i - 1$ and $i + 1$, where dragon $0$ is defined to be dragon $n$ and dragon $n + 1$ is defined to be dragon $1$. Additionally, dragons $x$ and $y$ are friends with each other (if they are already friends, this changes nothing). Note that all friendships are mutual. 24 25 Output $n$ non-negative integers $a_1, a_2, \ldots, a_n$ such that for each dragon $i$ ($1 \le i \le n$), the following holds: 26 27 * Let $f_1, f_2, \ldots, f_k$ be the friends of dragon $i$. Then $a_i = \operatorname{mex}(a_{f_1}, a_{f_2}, \ldots, a_{f_k})$.$^{\text{∗}}$ 28 29 $^{\text{∗}}$The minimum excluded (MEX) of a collection of integers $c_1, c_2, \ldots, c_m$ is defined as the smallest non-negative integer $t$ which does not occur in the collection $c$. 30 31 Input 32 33 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. 34 35 The first and only line of each test case contains three integers $n$, $x$, $y$ ($3 \le n \le 2 \cdot 10^5$, $1 \le x \lt y \le n$). 36 37 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 38 39 Output 40 41 For each test case, output $n$ space-separated non-negative integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) on a line that satisfy the condition in the statement. If there are multiple solutions, print any of them. It can be proven that under the problem constraints, a solution with $0 \le a_i \le 10^9$ always exists. 42 43 Example 44 45 Input 46 47 ``` 48 7 49 50 5 1 3 51 52 4 2 4 53 54 6 3 5 55 56 7 3 6 57 58 3 2 3 59 60 5 1 5 61 62 6 2 5 63 ``` 64 65 Output 66 67 ``` 68 0 2 1 0 1 69 1 2 1 0 70 1 2 0 1 2 0 71 0 1 2 0 1 0 1 72 2 0 1 73 1 0 2 1 0 74 0 1 2 0 2 1 75 ``` 76 77 Note 78 79 For the first test case: 80 81 * $i = 1$: Dragon $1$'s friends are dragons $2, 3, 5$. $\operatorname{mex}(a_2, a_3, a_5) = \operatorname{mex}(2, 1, 1) = 0 = a_1$, so the condition for dragon $1$ is satisfied. 82 * $i = 2$: Dragon $2$'s friends are dragons $1, 3$. $\operatorname{mex}(a_1, a_3) = \operatorname{mex}(0, 1) = 2 = a_2$. 83 * $i = 3$: Dragon $3$'s friends are dragons $1, 2, 4$. $\operatorname{mex}(a_1, a_2, a_4) = \operatorname{mex}(0, 2, 0) = 1 = a_3$. 84 * $i = 4$: Dragon $4$'s friends are dragons $3, 5$. $\operatorname{mex}(a_3, a_5) = \operatorname{mex}(1, 1) = 0 = a_4$. 85 * $i = 5$: Dragon $5$'s friends are dragons $1, 4$. $\operatorname{mex}(a_1, a_4) = \operatorname{mex}(0, 0) = 1 = a_5$.