#682. [Usaco2013 Dec]The Bessie Shuffle

[Usaco2013 Dec]The Bessie Shuffle

Description

Bessie有了一套新的做牌技术,M张牌被Bessie洗牌后,第i张牌会跑到p[i]的位置。现有N张牌从1..N编号,称为卡组。Bessie从卡组取前M张进行一次洗牌,然后将最上面的牌面朝下放置到一边的牌堆,剩下的牌面朝下放回卡组。重复此过程直至卡组剩下M-1张牌。接着Bessie将这M-1张牌逐一面朝下放到牌堆中。接下来有Q个询问,问第x[Q]张牌的编号。

Format

Input

第1行N, M, Q (2<=M <= N, 1<=Q <= 5,000)

接下来M行,每行一个p[i]

接下来Q行,每行是一个x[i], 表示一个询问

Output

对于每一个询问的编号

Samples

5 3 5
3
1
2
1
2
3
4
5
4
5
3
1
2

OUTPUT DETAILS:
The shuffle proceeds as:
[1, 2, 3, 4, 5] -> [2, 3, 1, 4, 5] (put 2 face down)
[3, 1, 4, 5] -> [1, 4, 3, 5] (put 1 face down)
[4, 3, 5] -> [3, 5, 4] (put 3 face down)
[5, 4] (put 5 face down)
[4] (put 4 face down)
This produces the final order of [4, 5, 3, 1, 2]

Limitation

100% 数据,N <= 1,000,000,000, M<=100,000