-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2084C.cpp
More file actions
63 lines (58 loc) · 973 Bytes
/
2084C.cpp
File metadata and controls
63 lines (58 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int n, a[maxn], b[maxn], m, p[maxn], ans[maxn][2];
inline void work(int x, int y) {
if (x == y) {
return;
}
ans[++m][0] = x;
ans[m][1] = y;
swap(a[x], a[y]);
swap(p[a[x]], p[a[y]]);
swap(b[x], b[y]);
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[a[i]] = i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
m = 0;
int x = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] == b[i]) {
if (n % 2 == 0 || x) {
cout << "-1\n";
return;
}
x = i;
} else if (b[p[b[i]]] != a[i]) {
cout << "-1\n";
return;
}
}
if (n & 1) {
work(x, (n + 1) / 2);
}
for (int i = 1; i <= n / 2; ++i) {
work(p[b[i]], n - i + 1);
}
cout << m << '\n';
for (int i = 1; i <= m; ++i) {
cout << ans[i][0] << ' ' << ans[i][1] << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}