Codeforces Round 972 (Div. 2)
B2
The Strict Teacher (Hard Version)
Codeforces
1200
原题
← B1C →
翻译中…

This is the hard version of the problem. The only differences between the two versions are the constraints on $m$ and $q$. In this version, $m, q \le 10^5$. You can make hacks only if both versions of the problem are solved.

翻译中…

Narek and Tsovak were busy preparing this round, so they have not managed to do their homework and decided to steal David's homework. Their strict teacher noticed that David has no homework and now wants to punish him. She hires other teachers to help her catch David. And now $m$ teachers together are chasing him. Luckily, the classroom is big, so David has many places to hide.

翻译中…

The classroom can be represented as a one-dimensional line with cells from $1$ to $n$, inclusive.

翻译中…

At the start, all $m$ teachers and David are in distinct cells. Then they make moves. During each move

翻译中…
  • David goes to an adjacent cell or stays at the current one.
  • Then, each of the $m$ teachers simultaneously goes to an adjacent cell or stays at the current one.
翻译中…

This continues until David is caught. David is caught if any of the teachers (possibly more than one) is located in the same cell as David. Everyone sees others' moves, so they all act optimally.

翻译中…

Your task is to find how many moves it will take for the teachers to catch David if they all act optimally.

翻译中…

Acting optimally means the student makes his moves in a way that maximizes the number of moves the teachers need to catch him; and the teachers coordinate with each other to make their moves in a way that minimizes the number of moves they need to catch the student.

翻译中…

Also, as Narek and Tsovak think this task is easy, they decided to give you $q$ queries on David's position.

翻译中…

Input

翻译中…

In the first line of the input, you are given a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. The description of each test case follows.

翻译中…

In the first line of each test case, you are given three integers $n$, $m$, and $q$ ($3 \le n \le 10^9$, $1 \le m, q \le 10^5$) — the number of cells on the line, the number of teachers, and the number of queries.

翻译中…

In the second line of each test case, you are given $m$ distinct integers $b_1, b_2, \ldots, b_m$ ($1 \le b_i \le n$) — the cell numbers of the teachers.

翻译中…

In the third line of each test case, you are given $q$ integers $a_1, a_2, \ldots, a_q$ ($1 \le a_i \le n$) — David's cell number for every query.

翻译中…

It is guaranteed that for any $i$, $j$ such that $1 \le i \le m$ and $1 \le j \le q$, $b_i \neq a_j$.

翻译中…

It is guaranteed that the sum of values of $m$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

It is guaranteed that the sum of values of $q$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $q$ lines, the $i$-th of them containing the answer of the $i$-th query.

翻译中…

Note

翻译中…

In the only query of the first example, the student can run to cell $1$. It will take the teacher five moves to reach from cell $6$ to cell $1$, so the answer is $5$.

翻译中…

In the second query of the second example, the student can just stay at cell $3$. The teacher, initially located in cell $4$, can reach cell $3$ in one move. Therefore, the answer is $1$.

翻译中…

样例

Input #1
2
8 1 1
6
3
10 3 3
1 4 8
2 3 10
Output #1
5
1
1
2
InputCopy OutputCopy
题目信息
题号
2005B2
时间限制
1.5 s
内存限制
256 MB
标签
二分
贪心
数学
排序

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