Codeforces Round 567 (Div. 2)
D
Irrigation
Codeforces
2200
原题
← BE1 →
翻译中…

Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first $n$ olympiads the organizers introduced the following rule of the host city selection.

翻译中…

The host cities of the olympiads are selected in the following way. There are $m$ cities in Berland wishing to host the olympiad, they are numbered from $1$ to $m$. The host city of each next olympiad is determined as the city that hosted the olympiad the smallest number of times before. If there are several such cities, the city with the smallest index is selected among them.

翻译中…

Misha's mother is interested where the olympiad will be held in some specific years. The only information she knows is the above selection rule and the host cities of the first $n$ olympiads. Help her and if you succeed, she will ask Misha to avoid flooding your house.

翻译中…

Input

翻译中…

The first line contains three integers $n$, $m$ and $q$ ($1 \leq n, m, q \leq 500\,000$) — the number of olympiads before the rule was introduced, the number of cities in Berland wishing to host the olympiad, and the number of years Misha's mother is interested in, respectively.

翻译中…

The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq m$), where $a_i$ denotes the city which hosted the olympiad in the $i$-th year. Note that before the rule was introduced the host city was chosen arbitrarily.

翻译中…

Each of the next $q$ lines contains an integer $k_i$ ($n + 1 \leq k_i \leq 10^{18}$) — the year number Misha's mother is interested in host city in.

翻译中…

Output

翻译中…

Print $q$ integers. The $i$-th of them should be the city the olympiad will be hosted in the year $k_i$.

翻译中…

Note

翻译中…

In the first example Misha's mother is interested in the first $10$ years after the rule was introduced. The host cities these years are 4, 3, 4, 2, 3, 4, 1, 2, 3, 4.

翻译中…

In the second example the host cities after the new city is introduced are 2, 3, 1, 2, 3, 5, 1, 2, 3, 4, 5, 1.

翻译中…

样例

Input #1
6 4 10
3 1 1 1 2 2
7
8
9
10
11
12
13
14
15
16
Output #1
4
3
4
2
3
4
1
2
3
4
InputCopy OutputCopy
Input #2
4 5 4
4 4 5 1
15
9
13
6
Output #2
5
3
3
3
InputCopy OutputCopy
题目信息
题号
1181D
时间限制
2.5 s
内存限制
512 MB
标签
二分
数据结构
模拟
排序
树
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。