Type: Default 1000ms 256MiB

彩色球

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题面描述

NN 个数 X1,2,,NX_{1,2,\dots,N},每个数有一个颜色 C1,2,,NC_{1,2,\dots,N}

Arisa 想要通过某些操作把这些数从小到大排好序。

她能进行下面这一系列操作任意次(可以不操作):

选择一个数 Xi(1iN1)X_i(1 \leq i \leq N - 1)

交换 XiX_iXi+1X_{i+1}

(如果 CiCi+1C_i \neq C_{i+1},她需要花费 11 的代价)

Arisa 想要花费最小的代价排序,她想知道最小的代价是多少。

输入格式

第一行一个整数 NN

第二行 NN 个整数 C1,2,,NC_{1,2,\dots,N}

第三行 NN 个整数 X1,2,,NX_{1,2,\dots,N}

输出格式

一个整数,表示最小代价。

样例

输入 1

5
1 5 2 2 1
3 2 1 2 1

输出 1

6

样例 1 解释

六次操作分别交换的位置为:1122223333444455334411222233

输入 2

3
1 1 1
3 2 1

输出 2

0

输入 3

3
3 1 2
1 1 2

输出 3

0

数据范围

  • 2N3×1052 \leq N \leq 3 \times 10^5
  • 1CiN1 \leq C_i \leq N
  • 1XiN1 \leq X_i \leq N

测试比赛功能

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2022-9-14 10:45
End at
2022-9-14 12:15
Duration
1.5 hour(s)
Host
Partic.
19