#FT0000053. Luân phiên tổ chức đại hội tưới tiêu (Irrigation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Luân phiên tổ chức đại hội tưới tiêu (Irrigation)
Irrigation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities numbered through . The host cities of the first years are given and were chosen arbitrarily. Starting with year , the host city is always the one that has hosted the fewest previous years. If several cities tie, the smallest city index is chosen.
Answer independent questions asking which city hosts year . Asked years may be extremely large and must not be simulated one by one.
Input
- Line 1: integers : initial years, cities, query count.
- Line 2: exactly host-city indices .
- Next lines: one queried year per line.
Output
Print lines; line gives the host city in year .
Subtasks
Subtask 1 (20 points):
- ; for all ; for every query.
Subtask 2 (30 points):
- ; for all ; for every query.
Subtask 3 (50 points):
- ; for all ; for every query.
Examples
Examples 1
Input
6 4 10
3 1 1 1 2 2
7
8
9
10
11
12
13
14
15
16
Output
4
3
4
2
3
4
1
2
3
4
Explanation
After six years, host counts of cities are . Years 7–9 choose cities . Years 10–12 choose to equalize all counts at 3. Subsequent years cycle through , producing the remaining answers.
Examples 2
Input
1 3 5
2
2
3
4
5
1000000000000000000
Output
1
3
1
2
1
Explanation
City 2 starts with one event while the other two have none. Years 2 and 3 choose 1 and 3. Starting in year 4 all counts are equal and hosts repeat as 1,2,3; year has offset divisible by three from year 4, so its host is 1.