博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C. Anya and Smartphone
阅读量:7255 次
发布时间:2019-06-29

本文共 4299 字,大约阅读时间需要 14 分钟。

C. Anya and Smartphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — 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 a1, a2, ..., an — the initial order of icons from left to right in the menu (from the first to the last one), ai —  is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.

The third line contains m integers b1, b2, ..., bm(1 ≤ bi ≤ n) — the ids of the launched applications in the planned order. One application may be launched multiple times.

Output

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

Sample test(s)
Input
8 3 3 1 2 3 4 5 6 7 8 7 8 1
Output
7
Input
5 4 2 3 1 5 2 4 4 4 4 4
Output
8
Note

In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.

After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures.

After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.

After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.

In total, Anya makes 7 gestures.

 

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std;14 const int INF=0x7fffffff;15 const double EXP=1e-8;16 const int MS=100005;17 const int mod=100000007;18 typedef long long LL;19 20 int pos[MS],id[MS];21 22 int main()23 {24 int n,m,k,i,x,y;25 scanf("%d %d %d",&n,&m,&k);26 for(i=0;i

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/4299363.html

你可能感兴趣的文章
电梯算法
查看>>
畅通工程续(最短路)
查看>>
operator的各种问题
查看>>
35个排版耳目一新的网站设计欣赏
查看>>
spring topic chat
查看>>
Nginx
查看>>
.NET跨平台:在Linux上基于ASP.NET 5用EF7生成数据库
查看>>
DataProtection设置问题引起不同ASP.NET Core站点无法共享用户验证Cookie
查看>>
Windows 上编译 corefx 源码生成 Linux 上可用的 System.Data.SqlClient.dll
查看>>
Sublime python 環境配置和交互加載
查看>>
Android Touch事件传递机制 一: OnTouch,OnItemClick(监听器),dispatchTouchEvent(伪生命周期)...
查看>>
十进制到62进制的转换
查看>>
python 后台运行命令
查看>>
【IOS】读取、保存图片的各种方法
查看>>
CCNA第二章
查看>>
CCNP路 由 选 择 原 理
查看>>
input 特殊字符限制
查看>>
ubuntu14.04配置python 配置OPENCV
查看>>
String类的subString(i)方法(基于jdk 1.9)
查看>>
Java并发包--ConcurrentLinkedQueue
查看>>