QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 2048 MB Points totaux : 100

#16200. 保安

Statistiques

在过去的几周里,Binary Casino 饱受当地针对周边赌场的犯罪浪潮之苦。尽管 Binary Casino 安装了监控摄像头,但由于赌场内几乎无人巡逻,小偷们通常能相对轻松地溜走。

在周五的所有收入被盗后,Binary Casino 的经理失去了耐心,决定通过雇佣大量保安来加强赌场的安保。然而,赌场里没有人能够制定出一个如何将保安分布在整个赌场以实现安全最大化的计划。因此,保安们毫无规律地分散在赌场各处。幸运的是,他们的位置可以用二维平面上的整数坐标来描述。

由于保安分布不均,一旦发生抢劫案,安保主管很难确定哪位保安距离事发地点最近。由于赌场空间受限,里面全是无尽的老虎机通道,这项任务变得更加困难。这种限制使得每位保安在从一个位置移动到另一个位置时,必须进行一系列的移动。在每一步中,他/她可以将自己的每个坐标改变 $1$、$0$ 或 $-1$。两个位置之间的距离等于保安从一个位置移动到另一个位置所需的最少步数。

给定保安的位置和一系列安全事件发生的位置,你的任务是计算每个事件到任何一位保安的最短距离。这将使安保主管能够通知最合适的保安,从而大大提高赌场的安全性。

输入格式

输入的第一行包含两个整数 $N$ 和 $Q$($1 \le N, Q \le 3 \cdot 10^5$),分别表示保安的数量和安全事件的数量。

接下来 $N$ 行,每行包含两个整数 $X$ 和 $Y$($0 \le X, Y \le 5000$),表示一个保安在二维平面上的坐标。

接下来 $Q$ 行,每行包含两个整数 $A$ 和 $B$($0 \le A, B \le 5000$),表示一个安全事件的坐标。

输出格式

对于 $Q$ 个安全事件中的每一个,输出一行,包含到任何一位保安的最短距离(以步数衡量)。

样例

输入样例 1

2 3
0 1
4 0
5 0
4 3
1 2

输出样例 1

1
3
1

输入样例 2

2 4
0 0
3 3
1 1
0 3
1 2
3 3

输出样例 2

1
3
2
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.