Pinely Round 5 (Div. 1 + Div. 2)
H
Cycle Sort
Codeforces
3500
原题
← G→
翻译中…

You are given two integer arrays $a_0, \ldots, a_{n - 1}$ and $b_0, \ldots, b_{m - 1}$. Each integer among $1, \ldots, n + m$ is present exactly once among $a_0, \ldots, a_{n - 1}, b_0, \ldots, b_{m - 1}$.

翻译中…

We perform $k$ operations on the arrays. Namely, for each integer $i$ from $0$ to $k - 1$ in this order

翻译中…
  • if $a_{i \bmod n} \gt b_{i \bmod m}$, we swap $a_{i \bmod n}$ and $b_{i \bmod m}$
  • otherwise, we do nothing
翻译中…

Determine the final state of both arrays after all $k$ operations are completed.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains three integers $n, m, k$ ($1 \leq n, m \leq 2 \cdot 10^5$, $0 \leq k \leq 10^{18}$).

翻译中…

The second line contains $n$ integers $a_0, \ldots, a_{n - 1}$.

翻译中…

The third line contains $m$ integers $b_0, \ldots, b_{m - 1}$.

翻译中…

It is guaranteed that the joint sequence $a_0, \ldots, a_{n - 1}, b_0, \ldots, b_{m - 1}$ is a permutation of integers from $1$ to $n + m$.

翻译中…

The sum of $n + m$ over all testcases doesn't exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each testcase, print two lines — the states of the arrays $a_0, \ldots, a_{n - 1}$ and $b_0, \ldots, b_{m - 1}$ after the $k$ operations are performed as described above.

翻译中…

Note

翻译中…

The action sequence for the first example

翻译中…

$i$$i \bmod n$$i \bmod m$comparisonactionarray $a$array $b$000$3 \gt 1$swap $a_0$ and $b_0$[1, 4][3, 5, 2]111$4 \lt 5$nothing[1, 4][3, 5, 2]202$1 \lt 2$nothing[1, 4][3, 5, 2]310$4 \gt 3$swap $a_1$ and $b_0$[1, 3][4, 5, 2]401$1 \lt 5$nothing[1, 3][4, 5, 2]

翻译中…

样例

Input #1
3
2 3 5
3 4
1 5 2
1 5 4
6
5 4 3 2 1
3 3 0
4 5 6
1 2 3
Output #1
1 3
4 5 2
2
6 5 4 3 1
4 5 6
1 2 3
InputCopy OutputCopy
题目信息
题号
2161H
时间限制
2 s
内存限制
512 MB
标签
数据结构

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