#P3483. [POI2009] STR-Fire Brigade

[POI2009] STR-Fire Brigade

题目描述

In the capital of Byteotia, Bytau, the layout of streets is highly regular. Every street leads either from north to south, or from east to west. Therefore every north-south street intersects every east-west street in exactly one spot. Furthermore, along every street its successive intersections are exactly 1 km apart.

Bytau is not only the capital, but also one of the oldest cities in Byteotia. No wonder that there are as many as historic buildings, each at one of the intersections. The City Council cares for their protection very much, and is now concerned with the risk of fire. Hence they have decided to establish two main fire stations in the city. Each monument is going to be protected by the nearest station; by both, should both fire stations be equally close.

Housing is very dense in Bytau, so Euclidean distance is not the measure of choice. The distance between a monument and fire station should rather be defined as the length of the shortest path along the streets between them.

The City Council has prepared several projects of the stations' location. And you have been asked to determine, for each of them, the number of monuments protected by: the first station only, the second station only, and both stations, respectively.

输入格式

In the first line of the standard input there are four integers nn, mm, zz and pp (1n,m1,000,000,0001\le n,m\le 1{,}000{,}000{,}000, 1z,p100,0001\le z,p\le 100{,}000) separated by single spaces and denoting respectively: the number of streets leading from north to south, the number of streets leading from east to west, the number of historic buildings in Bytau, and the number of projects proposed by the City Council.

The north-south streets are numbered from 11 to nn, west to east. The east-west streets are numbered from 11 to mm, north to south. The intersection of xx-th north-south and yy-th east-west street will be denoted by the coordinates (x,y)(x,y).

In each of the following lines there are two integers xix_i and yiy_i (1xin1 ≤ xi ≤ n, 1yim1 ≤ yi ≤ m) separated by a single space and denoting the coordinates of the i-th monument. No pair of different monuments is located at the same intersection.

Each of the following pp lines contains one proposal of the City Council - four integers xj,1,yj,1,xj,2,yj,2x_{j,1}, y_{j,1}, x_{j,2}, y_{j,2} separated by single spaces, 1xj,1,xj,2n1 ≤ x_{j,1},x_{j,2} ≤ n, 1yj,1,yj,2m1 ≤ y_{j,1},y_{j,2} ≤ m, (xj,1,yj,1)(xj,2,yj,2)(x_{j,1},y_{j,1})≠(x_{j,2},y_{j,2}). The coordinates (xj,1,yj,1)(x_{j,1},y_{j,1}) and (xj,2,yj,2)(x_{j,2},y_{j,2}) describe the intersections at which the fire stations are to be located according to the jj-th proposal (1jp)(1 ≤ j ≤ p).

输出格式

Your programme should print out exactly pp lines on the standard output.

There should be three integers in the jj-th line, denoting:

the number of monuments protected by the first station of jj-th proposal of the City Council only, the number of monuments protected by the second station only and the number of monuments protected by both stations, respectively.

These numbers should be separated by single spaces.

题目大意

平面上有 zz 个点,给你 pp 个形如 p1(x1,y1),p2(x2,y2)p_1(x_1,y_1),p_2(x_2,y_2) 的询问,要你求出 zz 个点中离 p1p_1 更近的点,离 p2p_2 更近的点,与 p1p_1p2p_2 的距离相等的点各有多少个。这里的距离指的是曼哈顿距离,即x坐标之差的绝对值加上y坐标之差的绝对值。

6 5 6 1
1 2
6 5
5 1
3 3
3 4
4 1
2 3 4 3

1 3 2