Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2)
C
You Soared Afar With Grace
Codeforces
1400
原题
← BD →
翻译中…

You are given a permutation $a$ and $b$ of length $n$$^{\text{∗}}$. You can perform the following operation at most $n$ times:

翻译中…
  • Choose two indices $i$ and $j$ ($1 \le i, j \le n$, $i \ne j$), swap $a_i$ with $a_j$, swap $b_i$ with $b_j$.
翻译中…

Determine whether $a$ and $b$ can be reverses of each other after operations. In other words, for each $i = 1, 2, \ldots, n$, $a_i = b_{n + 1 - i}$.

翻译中…

If it is possible, output any valid sequence of operations. Otherwise, output $-1$.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

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 a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the permutations.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$).

翻译中…

The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le n$).

翻译中…

It is guaranteed that $a$ and $b$ are permutations of length $n$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, if it is impossible, output $-1$ in the only line. Otherwise, output a single integer $m$ ($0 \le m \le n$) — the number of operations in the first line. In the following $m$ lines, output two integers — the indices $i$ and $j$ ($1 \le i, j \le n$, $i \ne j$) in each operation in order. If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

In the second test case, $b$ is already the reverse of $a$.

翻译中…

In the third test case, after performing the following operation, $b$ will become the reverse of $a$:

翻译中…
  • Swap $a_1, a_2$ and swap $b_1, b_2$. Now $a = [3, 1, 2, 4]$ and $b = [4, 2, 1, 3]$.
翻译中…

In the fourth test case, after performing the following operations in order, $b$ will become the reverse of $a$:

翻译中…
  • Swap $a_1, a_2$ and swap $b_1, b_2$. Now $a = [5, 2, 1, 3, 4]$ and $b = [5, 3, 4, 2, 1]$.
  • Swap $a_1, a_3$ and swap $b_1, b_3$. Now $a = [1, 2, 5, 3, 4]$ and $b = [4, 3, 5, 2, 1]$.
翻译中…

样例

Input #1
5
2
1 2
1 2
2
1 2
2 1
4
1 3 2 4
2 4 1 3
5
2 5 1 3 4
3 5 4 2 1
5
3 1 2 4 5
1 2 3 4 5
Output #1
-1
0
1
1 2
2
1 2
1 3
-1
InputCopy OutputCopy
题目信息
题号
2084C
时间限制
2 s
内存限制
256 MB
标签
构造
数据结构
贪心
模拟

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