COI '14 #3 Ogledala

View as PDF

Submit solution


Points: 30 (partial)
Time limit: 4.0s
Memory limit: 512M

Problem type

There are M modern washbasins numbered from 1 to M from left to right in the ladies' room of an enormous shopping centre.

Currently, there are N ladies in the restroom (numbered from 1 to N) and they've occupied the washbasins with numbers A_1, A_2, \dots, A_N. Soon there will be M - N more ladies arriving (numbered from N + 1 to M in the order of arrival) that will occupy all the remaining available washbasins. The ladies arriving primarily want their privacy, so each of them always chooses an available washbasin by the following procedure:

  • First she finds the largest consecutive series of available washbasins. If there is more than one, she chooses the leftmost.
  • After that, she occupies the middle washbasin in the chosen series. If the series is of even length, she chooses the left of the two middle washbasins.

It is safe to assume that none of the ladies will leave the washbasin in the foreseeable future.

Write a programme that will, for each of Q given integers B_i, determine the label of the washbasin that will be occupied by the lady marked with B_i.

Input Specification

The first line of input contains integers M, N, and Q – the number of washbasins, the initial number of ladies in the restroom and the number of ladies for which you need to determine which washbasin they will use.

The second line of input contains N space-separated integers, the i^\text{th} of those numbers is A_i – the label of the washbasin that is being used by lady i.

The third line of input contains Q space-separated integers, the i^\text{th} of those numbers is B_i – the label of the lady for which we want to know which washbasin she will use.

The first N ladies in the restroom haven't necessarily chosen their washbasins using the procedure described in the task.

The arrays A and B are strictly increasing. In other words, it holds 1 \le A_1 < A_2 < \dots < A_N \le M and 1 \le B_1 < B_2 < \dots < B_Q \le M.

Output Specification

Output Q lines. The i^\text{th} line must contain the label of the washbasin that will be used by the lady labeled B_i.

Please note: We recommend that you use a 64-bit integer data type (int64 in Pascal, long long in C/C++).

Constraints

For all subtasks:

1 \le Q \le 10^5

N \le M

1 \le N \le 10^5

Subtask Score Constraints
1 19 1 \le M \le 300\,000
2 22 1 \le M \le 10^{14}, B_Q \le 300\,000
3 59 1 \le M \le 10^{14}

Sample Input 1

7 1 4
4
2 3 4 5

Sample Output 1

2
6
1
3

Sample Input 2

10 2 4
2 8
1 3 5 8

Sample Output 2

2
5
6
4

Explanation for Sample Output 2

The first two ladies occupy the washbasins 2 and 8 (respectively).

The remaining ladies occupy the washbasins 5, 3, 6, 9, 1, 4, 7, and 10, respectively.


Comments

There are no comments at the moment.