QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10298. 公交

统计

在一条公路上均匀分布着 $L$ 个公交车站,由 $1$ 至 $L$ 编号。初始有 $n$ 个乘客在等公交,第 $i$ 个乘客在 $s_i$ 号车站等车,目的地是 $t_i$ 号车站。保证 $s_i \neq t_i$ 。

这条公路上运行着恰好一辆公交车,初始公交车停在 $p$ 号车站。

若公交车在 $i$ 号车站,则可以花费一个单位时间移动到 $(i-1)$ 号或 $(i+1)$ 号车站,需要保证车站编号在 $[1,L]$ 内。在初始车站或由一个车站移动至另一个车站后,公交车会开门接上所有在这个车站等车的乘客,并放下所有以这个车站为目的地的车上的乘客。

假定公交车有无穷的容量,公交车在车站之间的移动可以任意选择,且乘客上下车不消耗时间,你需要求出公交车最少需要多少单位时间才能将所有 $n$ 个乘客载至目的地。

由于没有人知道初始公交车停在哪里,所以你还需要解决 $q$ 次询问,每次询问将给出不同的 $p$,而乘客的信息保持不变。你需要对于每组询问都求出上述问题的答案。

输入格式

从标准输入读入数据。

第一行输入一个正整数 $id$,表示子任务编号。

  • 第一行三个整数 $L, n, q$,表示公交车站数量、乘客数量和询问数量。
  • 接下来 $n$ 行每行两个整数 $s_i, t_i$,描述一个乘客。
  • 接下来一行 $q$ 个整数 $p_1,p_2,\cdots, p_q$,描述每组询问的 $p$ 的值。

输出格式

输出到标准输出。

对于每组测试数据输出一行 $q$ 个整数 $a_1,a_2,\cdots, a_q$ 依次表示每组询问的答案。

样例

输入

1
20 2 3
3 5
10 12
2 6 9

输出

10 12 14

解释

  • 第一组询问中 $p = 2$,公交车的最优移动方式为:不断让所在车站编号加一,花十个单位时间移动到 $12$。
  • 第二组询问中 $p = 6$,公交车的最优移动方式为:先花三个单位时间移动到 $3$,再花九个单位时间移动到 $12$。
  • 第三组询问中 $p = 9$,公交车的最优移动方式为:先花三个单位时间移动到 $12$,再花九个单位时间移动到 $3$,最后花两个单位时间移动到 $5$。

样例

输入

1
10 10 10
7 3
6 5
8 3
10 8
7 1
4 7
7 9
6 2
1 9
10 1
9 2 10 3 1 6 8 4 5 7

输出

18 19 17 20 18 21 19 21 22 20

子任务

对于所有测试数据,

  • $1 \le L \le 10^{16}$,$1 \le n, q \le 10^{6}$;
  • $\forall 1 \le i \le n, 1 \le s_i, t_i \le L, s_i \neq t_i$;
  • $1 \le p_1, p_2, \cdots, p_q \le L$;
  • $\forall 1 \le i \le n, 1 \le j \le q, s_i \neq p_j, t_i \ne p_j$。

子任务编号分值$n,q \le$特殊性质
113$10$A
214$50$
38$3,000$B
412
513$10^{6}$B
616C
724

特殊性质 A:$L \le 10$。

特殊性质 B:$\forall 1 \le i \le n, 1 \le j \le q, p_j < s_i$。

特殊性质 C:$\forall 1 \le i \le n, 1 \le j \le q, p_j \not\in [\min(s_i,t_i), \max(s_i,t_i)]$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.