AtCoder Grand Contest 065
翻译中…
Problem Statement
翻译中…
You are given two sequences of positive integers of length $N$, $A=(A_1,A_2,\dots,A_N)$ and $B=(B_1,B_2,\dots,B_N)$.
翻译中…
Find the minimum possible inversion number of a sequence of positive integers $C=(C_1,C_2,\dots,C_N)$ such that the $i$-th element $C_i$ is $A_i$ or $B_i$.
翻译中…
Solve $T$ test cases.
翻译中…
Constraints
翻译中…
$1 \le T$$1 \le N \le 5 \times 10^5$$1 \le A_i,B_i \le \color{red}{\boldsymbol{3}}$- The sum of
$N$for all test cases in a single input is at most$5 \times 10^5$.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
翻译中…
Here, $\mathrm{case}_i$ represents the $i$-th test case. Each test case is given in the following format:
翻译中…
N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
8
3
2 1 1
3 3 2
5
2 1 3 2 2
1 2 1 2 3
8
2 1 3 3 3 1 2 2
1 2 3 1 2 1 3 2
10
1 3 2 1 1 3 2 2 2 2
2 3 1 1 1 1 3 1 3 3
12
2 1 1 3 3 1 3 3 2 2 2 1
3 1 1 3 3 1 3 2 3 2 1 2
15
1 3 1 3 3 2 2 1 2 3 3 3 1 1 3
3 3 3 2 3 2 1 3 2 1 2 2 3 3 3
18
3 1 1 3 3 2 1 1 2 3 2 1 3 3 3 2 2 3
1 1 3 2 1 3 1 2 1 2 3 2 2 1 3 1 3 3
20
2 2 3 1 1 3 2 3 3 1 3 1 2 1 2 2 1 2 3 2
1 1 1 3 3 1 1 3 2 2 1 1 1 1 1 2 2 2 2 1
Output #1
1
0
6
6
20
9
5
17
For the first test case, an optimal solution is $C=(2,3,2)$ with the inversion number of $1$.
For the second test case, an optimal solution is $C=(1,1,1,2,3)$ with the inversion number of $0$.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。