#abc233h. Ex - Manhattan Christmas Tree

Ex - Manhattan Christmas Tree

Score : 600600 points

问题描述

在二维平面上有 NN 棵圣诞树。第 ii 棵树位于坐标 (xi,yi)(x_i, y_i)

接下来回答 QQ 个查询。

查询 ii: 点 (ai,bi)(a_i, b_i) 与其第 KiK_i 近的圣诞树之间的曼哈顿距离是多少?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN Christmas trees in the two-dimensional plane. The ii-th tree is at coordinates (xi,yi)(x_i,y_i).

Answer the following QQ queries.

Query ii: What is the distance between (ai,bi)(a_i,b_i) and the KiK_i-th nearest Christmas tree to that point, measured in Manhattan distance?

Constraints

  • 1N1051\leq N \leq 10^5
  • 0xi1050\leq x_i\leq 10^5
  • 0yi1050\leq y_i\leq 10^5
  • (xi,yi)(xj,yj)(x_i,y_i) \neq (x_j,y_j) if iji\neq j.
  • 1Q1051\leq Q \leq 10^5
  • 0ai1050\leq a_i\leq 10^5
  • 0bi1050\leq b_i\leq 10^5
  • 1KiN1\leq K_i\leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

\vdots

xNx_N yNy_N

QQ

a1a_1 b1b_1 K1K_1

\vdots

aQa_Q bQb_Q KQK_Q

Output

Print QQ lines.
The ii-th line should contain the answer to Query ii.

Sample Input 1

4
3 3
4 6
7 4
2 5
6
3 5 1
3 5 2
3 5 3
3 5 4
100 200 3
300 200 1

Sample Output 1

1
2
2
5
293
489

The distances from (3,5)(3,5) to the 11-st, 22-nd, 33-rd, 44-th trees to that point are 22, 22, 55, 11, respectively.
Thus, the answers to the first four queries are 11, 22, 22, 55, respectively.

update @ 2024/3/10 10:09:37