QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#6838. 仮定こそがすべて

Statistics

JB は、問題を解くには仮定さえあればよいと信じています。それを証明するために、JB は $1$ から $n$ までの数の順列 $A$ と $B$ をあなたに与え、次の条件を満たす、$A$ の要素を交換する操作列 $(x_i,y_i)$ を出力してほしいと考えています。

  1. 交換する各要素対は転倒を構成します(つまり、第 $i$ 回の操作を行う時点で $x_i<y_i$ かつ $A_{x_i}>A_{y_i}$ です)。

  2. 操作列の終了時に $A$ が $B$ になります。

または、不可能であると判定してください。この問題を解いて JB の信念の証明を手伝ってください!

入力

複数のテストケースがあります。入力の最初の行には、テストケース数を表す整数 $T$ が与えられます。各テストケースについて:

最初の行には、$A$ と $B$ の要素数を表す整数 $n$($1\le n\le 2021$)が与えられます。

次の行には、配列 $A$ を表す相異なる $n$ 個の整数 $A_1,A_2,\ldots,A_n$($1\le A_i\le n$)が与えられます。

3 行目には、配列 $B$ を表す相異なる $n$ 個の整数 $B_1,B_2,\ldots,B_n$($1\le B_i\le n$)が与えられます。

すべてのテストケースにわたる $n$ の合計は $2021$ 以下であることが保証されます。

出力

各テストケースについて、そのような操作列が存在しない場合は、整数 -1 を含む 1 行を出力してください。

そうでなければ、最初の行に操作列の長さを表す整数 $k$($0\le k\le \frac{n(n-1)}2$)を出力してください。続いて $k$ 行を出力し、各行には第 $i$ 回の操作 $\operatorname{swap}(A_{x_i},A_{y_i})$ を表す 2 つの整数 $x_i,y_i$($1\le x_i<y_i\le n$)を出力してください。

入出力例

入力 1

3
2
1 2
2 1
4
4 1 2 3
1 3 2 4
8
8 7 6 5 4 3 2 1
1 8 7 6 5 4 3 2

出力 1

-1
2
1 2
2 4
7
7 8
6 7
5 6
4 5
3 4
2 3
1 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.