QOJ.ac

QOJ

Límite de tiempo: 5 s Límite de memoria: 512 MB Puntuación total: 100 Dificultad: [mostrar]

#3059. 水牛路障

Estadísticas

西部荒野的一片牧场可以表示为嵌入在标准坐标系第一象限中的矩形网格。一群 $n$ 头水牛散布在网格中,每头水牛占据一个单位正方形。水牛编号为 $1$ 到 $n$;第 $j$ 头水牛位于右上角坐标为 $(x_j, y_j)$ 的单位正方形内。坐标轴代表两条在原点相交的河流,限制了水牛向左和向下的移动。

总共有 $m$ 位定居者陆续到达,每位定居者通过以下步骤圈占一块土地:

  1. 定居者选择一个整数坐标点,并在该点安装一个栅栏桩。保证他选择的点没有被任何先前安装的栅栏桩或栅栏占用。此外,没有任何两个栅栏桩具有相同的 $x$ 坐标,也没有任何两个栅栏桩具有相同的 $y$ 坐标。
  2. 从栅栏桩开始,定居者分别向左和向下建造水平和垂直的栅栏段。每一段栅栏都尽可能地长,即直到它到达河流或其他栅栏为止。
  3. 定居者圈占所有由栅栏和河流围成的连通区域,且该区域的右上角为其栅栏桩所在位置。当然,他也圈占了区域内的所有水牛。注意,后来的定居者可能会圈占先前定居者已经圈占过的土地。

对于每位定居者,求出他到达时所圈占的水牛总数。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 300\,000$),表示水牛的数量。接下来的 $n$ 行中,第 $j$ 行包含两个整数 $x_j$ 和 $y_j$ ($1 \le x_j, y_j \le 10^9$),表示第 $j$ 头水牛的位置。没有两头水牛位于相同的位置。

接下来一行包含一个整数 $m$ ($1 \le m \le 300\,000$),表示定居者的数量。接下来的 $m$ 行中,第 $j$ 行包含两个整数 $x'_j$ 和 $y'_j$ ($1 \le x'_j, y'_j \le 10^9$),表示第 $j$ 位定居者安装的栅栏桩坐标。所有的 $x'_j$ 互不相同,所有的 $y'_j$ 也互不相同。

输出格式

输出 $m$ 行。第 $j$ 行应包含第 $j$ 位定居者到达时所圈占的水牛数量。

样例

输入 1

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

输出 1

2
1
3
2

说明

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.