311170: CF1944B. Equal XOR

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Equal XORtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given an array $a$ of length $2n$, consisting of each integer from $1$ to $n$ exactly twice.

You are also given an integer $k$ ($1 \leq k \leq \lfloor \frac{n}{2} \rfloor $).

You need to find two arrays $l$ and $r$ each of length $\mathbf{2k}$ such that:

  • $l$ is a subset$^\dagger$ of $[a_1, a_2, \ldots a_n]$
  • $r$ is a subset of $[a_{n+1}, a_{n+2}, \ldots a_{2n}]$
  • bitwise XOR of elements of $l$ is equal to the bitwise XOR of elements of $r$; in other words, $l_1 \oplus l_2 \oplus \ldots \oplus l_{2k} = r_1 \oplus r_2 \oplus \ldots \oplus r_{2k}$

It can be proved that at least one pair of $l$ and $r$ always exists. If there are multiple solutions, you may output any one of them.

$^\dagger$ A sequence $x$ is a subset of a sequence $y$ if $x$ can be obtained by deleting several (possibly none or all) elements of $y$ and rearranging the elements in any order. For example, $[3,1,2,1]$, $[1, 2, 3]$, $[1, 1]$ and $[3, 2]$ are subsets of $[1, 1, 2, 3]$ but $[4]$ and $[2, 2]$ are not subsets of $[1, 1, 2, 3]$.

Input

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 5000$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains $2$ integers $n$ and $k$ ($2 \le n \le 5 \cdot 10^4$, $1 \leq k \leq \lfloor \frac{n}{2} \rfloor $).

The second line contains $2n$ integers $a_1, a_2, \ldots, a_{2n}$ ($1 \le a_i \le n$). It is guaranteed that every integer from $1$ to $n$ occurs exactly twice in $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^4$.

Output

For each test case, output two lines.

On the first line of output, output $2k$ integers $l_1, l_2, \ldots, l_{2k}$.

On the second line of output, output $2k$ integers $r_1, r_2, \ldots r_{2k}$.

If there are multiple solutions, you may output any one of them.

ExampleInput
4
2 1
1 2 2 1
6 1
6 4 2 1 2 3 1 6 3 5 5 4
4 1
1 2 3 4 1 2 3 4
6 2
5 1 3 3 5 1 2 6 4 6 4 2
Output
2 1
2 1
6 4
1 3
1 2
1 2
5 1 3 3
6 4 2 4
Note

In the first test case, we choose $l=[2,1]$ and $r=[2,1]$. $[2, 1]$ is a subset of $[a_1, a_2]$ and $[2, 1]$ is a subset of $[a_3, a_4]$, and $2 \oplus 1 = 2 \oplus 1 = 3$.

In the second test case, $6 \oplus 4 = 1 \oplus 3 = 2$.

Output

题目大意:

给定一个长度为 $2n$ 的数组 $a$,包含从 $1$ 到 $n$ 每个整数恰好两遍。还给定一个整数 $k$($1 \leq k \leq \lfloor \frac{n}{2} \rfloor$)。需要找到两个数组 $l$ 和 $r$,每个数组的长度都是 $2k$,满足以下条件:

- $l$ 是 $[a_1, a_2, \ldots a_n]$ 的一个子集
- $r$ 是 $[a_{n+1}, a_{n+2}, \ldots a_{2n}]$ 的一个子集
- $l$ 中元素的按位异或(XOR)结果等于 $r$ 中元素的按位异或结果;即 $l_1 \oplus l_2 \oplus \ldots \oplus l_{2k} = r_1 \oplus r_2 \oplus \ldots \oplus r_{2k}$

至少存在一对符合条件的 $l$ 和 $r$。如果有多个解,可以输出其中任意一个。

输入输出数据格式:

输入:
- 第一行包含一个整数 $t$($1 \leq t \leq 5000$),表示测试用例的数量。
- 每个测试用例包含三行:
- 第一行包含两个整数 $n$ 和 $k$($2 \le n \le 5 \cdot 10^4$,$1 \leq k \leq \lfloor \frac{n}{2} \rfloor$)。
- 第二行包含 $2n$ 个整数 $a_1, a_2, \ldots, a_{2n}$($1 \le a_i \le n$),保证从 $1$ 到 $n$ 每个整数在 $a$ 中恰好出现两遍。
- 所有测试用例的 $n$ 之和不超过 $5 \cdot 10^4$。

输出:
- 对于每个测试用例,输出两行:
- 第一行输出 $2k$ 个整数 $l_1, l_2, \ldots, l_{2k}$。
- 第二行输出 $2k$ 个整数 $r_1, r_2, \ldots r_{2k}$。
- 如果有多个解,可以输出其中任意一个。题目大意: 给定一个长度为 $2n$ 的数组 $a$,包含从 $1$ 到 $n$ 每个整数恰好两遍。还给定一个整数 $k$($1 \leq k \leq \lfloor \frac{n}{2} \rfloor$)。需要找到两个数组 $l$ 和 $r$,每个数组的长度都是 $2k$,满足以下条件: - $l$ 是 $[a_1, a_2, \ldots a_n]$ 的一个子集 - $r$ 是 $[a_{n+1}, a_{n+2}, \ldots a_{2n}]$ 的一个子集 - $l$ 中元素的按位异或(XOR)结果等于 $r$ 中元素的按位异或结果;即 $l_1 \oplus l_2 \oplus \ldots \oplus l_{2k} = r_1 \oplus r_2 \oplus \ldots \oplus r_{2k}$ 至少存在一对符合条件的 $l$ 和 $r$。如果有多个解,可以输出其中任意一个。 输入输出数据格式: 输入: - 第一行包含一个整数 $t$($1 \leq t \leq 5000$),表示测试用例的数量。 - 每个测试用例包含三行: - 第一行包含两个整数 $n$ 和 $k$($2 \le n \le 5 \cdot 10^4$,$1 \leq k \leq \lfloor \frac{n}{2} \rfloor$)。 - 第二行包含 $2n$ 个整数 $a_1, a_2, \ldots, a_{2n}$($1 \le a_i \le n$),保证从 $1$ 到 $n$ 每个整数在 $a$ 中恰好出现两遍。 - 所有测试用例的 $n$ 之和不超过 $5 \cdot 10^4$。 输出: - 对于每个测试用例,输出两行: - 第一行输出 $2k$ 个整数 $l_1, l_2, \ldots, l_{2k}$。 - 第二行输出 $2k$ 个整数 $r_1, r_2, \ldots r_{2k}$。 - 如果有多个解,可以输出其中任意一个。

加入题单

上一题 下一题 算法标签: