题库练习 Anya and Smartphone
← 上一题 下一题 →

A9832 | Anya and Smartphone

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly $n$ applications, each application has its own icon. The icons are located on different screens, one screen contains $k$ icons. The icons from the first to the $k$ -th one are located on the first screen, from the $(k+1)$ -th to the $2k$ -th ones are on the second screen and so on (the last screen may be partially empty).

Initially the smartphone menu is showing the screen number $1$ . To launch the application with the icon located on the screen $t$ , Anya needs to make the following gestures: first she scrolls to the required screen number $t$ , by making $t-1$ gestures (if the icon is on the screen $t$ ), and then make another gesture — press the icon of the required application exactly once to launch it.

After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number $1$ .

All applications are numbered from $1$ to $n$ . We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.

Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?

Note that one application may be launched multiple times.

输入格式

The first line of the input contains three numbers $n,m,k$ ( $1<=n,m,k<=10^{5}$ ) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.

The next line contains $n$ integers, permutation $a_{1},a_{2},...,a_{n}$ — the initial order of icons from left to right in the menu (from the first to the last one), $a_{i}$ — is the id of the application, whose icon goes $i$ -th in the menu. Each integer from $1$ to $n$ occurs exactly once among $a_{i}$ .

The third line contains $m$ integers $b_{1},b_{2},...,b_{m}(1<=b_{i}<=n)$ — the ids of the launched applications in the planned order. One application may be launched multiple times.

输出格式

Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.

输入输出样例

输入 #1
8 3 3
1 2 3 4 5 6 7 8
7 8 1
输出 #1
7
输入 #2
5 4 2
3 1 5 2 4
4 4 4 4
输出 #2
8
C++ 编辑器
输入
输出