CF1681C.Double Sort

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two arrays aa and bb , both consisting of nn integers.

In one move, you can choose two indices ii and jj ( 1i,jn1 \le i, j \le n ; iji \neq j ) and swap aia_i with aja_j and bib_i with bjb_j . You have to perform the swap in both arrays.

You are allowed to perform at most 10410^4 moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.

输入格式

The first line contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of testcases.

The first line of each testcase contains a single integer nn ( 2n1002 \le n \le 100 ) — the number of elements in both arrays.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ain1 \le a_i \le n ) — the first array.

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n ( 1bin1 \le b_i \le n ) — the second array.

输出格式

For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most 10410^4 moves, print -1. Otherwise, first, print the number of moves kk (0k104)(0 \le k \le 10^4) . Then print ii and jj for each move (1i,jn(1 \le i, j \le n ; ij)i \neq j) .

If there are multiple answers, then print any of them. You don't have to minimize the number of moves.

输入输出样例

  • 输入#1

    3
    2
    1 2
    1 2
    2
    2 1
    1 2
    4
    2 3 1 2
    2 3 2 3

    输出#1

    0
    -1
    3
    3 1
    3 2
    4 3
首页