#P4737. [CERC2017] Buffalo Barricades
[CERC2017] Buffalo Barricades
题目描述
A pasture in the wild west can be represented as a rectangular grid embedded in the upper-right quadrant of a standard coordinate system. A herd of buffalos is scattered throughout the grid, each occupying a unit square. Buffalos are numbered through ; buffalo is located in the unit square whose upper-right corner is the point with integer coordinates . The coordinate axes represent two rivers meeting at the origin, restricting buffalo movement downwards and leftwards.
A total of settlers arrive, one by one, and each claims a piece of land using the following procedure:
- The settler picks a point with integer coordinates and installs a single fence post at that point.The point he picks is guaranteed to be free of any previously installed fence posts or fences.Moreover, no two fence posts will have the same -coordinate and no two fence posts will have the same -coordinates.
- Starting from the fence post, the settler builds horizontal and vertical fence segments leftwards and downwards, respectively. Each segment is built to be as long as possible — i. e. until it reaches the river or another fence.
- The settler claims all the land in the connected area bounded with fences and rivers whose upper-right corner is his fence post. Of course, he claims all the buffalos inside as well. Note that settlers arriving later may claim pieces of land already claimed by earlier settlers.
For each settler, find the total number of buffalos he claimed when he arrived.
输入格式
The first line contains an integer — the number of buffalos. The of the following lines contains two integers and — the location of the buffalo.No two buffalos will share the same location. The following line contains an integer — the number of settlers. The of the following lines contains two integers and — the coordinates of the fence postinstalled by the settler. All are different and all are different.
输出格式
Output lines. The line should contain the number of buffalos claimed by the settler upon arrival.
题目大意
【题目描述】
(西进运动时期)美国西部的一块牧场可以被表示为坐标系第一象限中的一块矩形网格。有 头水牛在其中分布着,每一头都占据着一个单位正方形。水牛们从 到 编号; 号水牛位于右上角坐标为 的单位正方形中。坐标轴表示了两条交汇于原点处的河流,阻止水牛向左下方移动。
一共有 个殖民者接连到达,每个人都要宣称一块土地的所有权,其过程遵循以下规则:
- 殖民者选定一个整数坐标点,并在此处安装一个栅栏柱。他选定的点必须没有被此前安装的栅栏或栅栏柱占据。并且,不存在两个栅栏柱会拥有相同的 坐标,也不存在两个栅栏柱会拥有相同的 坐标。
- 从栅栏柱开始,殖民者分别朝着左侧或下侧修建水平或竖直的栅栏片段。每段栅栏都修建得尽可能长:即直到碰到了河流或另一段栅栏才停下。
- 殖民者宣称以他的栅栏柱为右上角的,被栅栏和河流包围住的连通区域的所有权。当然,他也宣称了其中的所有水牛的所有权。注意后到来的殖民者也有可能宣称了已被先到来的殖民者宣称过的土地。
对于每个殖民者,请求出当他刚到来时,被他宣称了所有权的水牛的数量。
【输入格式】
第一行一个正整数 ,表示水牛的个数。
接下来 行,第 行两个正整数 ,表示第 头水牛的位置,不存在两头水牛的位置重合。
接下来一行一个正整数 ,表示殖民者的个数。
接下来 行,第 行两个正整数 ,表示第 个殖民者安装的栅栏柱的位置,所有 互不相同,所有 互不相同。
【输出格式】
输出 行,第 行一个整数,表示第 个殖民者刚到来时,被他宣称了所有权的水牛的数量。
【数据范围】
对于全部数据,,,所有有序数对 互不相同,所有 互不相同,所有 互不相同。
翻译来源:IOI 2021 集训队第一部分作业,PinkRabbit。
7
1 1
4 2
6 2
5 3
2 5
4 7
7 5
4
4 4
8 2
9 6
6 5
2
1
3
2