#6874. [2019 KAIST RUN Fall] Maximizer
[2019 KAIST RUN Fall] Maximizer
[2019 KAIST RUN Fall] Maximizer
题目描述
Maximizer has two permutations $A=[a_1,a_2,\cdots,a_N]$ and $B=[b_1,b_2,\cdots,b_N]$. Both $A, B$ have length $N$ and consists of $\textbf{distinct integers}$ from $1$ to $N$.Maximizer wants to maximize the sum of differences of each element, . But he can only swap two adjacent elements in . Precisely, he can only swap and for some from to . He can swap as many times as he wants.
What is the minimum number of swaps required for maximizing the difference sum?
输入格式
The first line contains an integer $N$. ($1 \leq N \leq 250 000$)The second line contains integers ().
The third line contains integers ().
Each of and is a permutation. In other words, it is consisted of distinct integers from to .
输出格式
Print an integer, the minimum number of swaps required for maximizing the difference sum.3
1 2 3
1 2 3
2
4
3 4 1 2
3 2 4 1
3