#abc234h. Ex - Enumerate Pairs

Ex - Enumerate Pairs

Score : 600600 points

问题描述

给定 NN 对整数 (xi,yi)(x_i, y_i),编号从 11NN,以及一个整数 KK

按输出格式列出满足以下条件的所有整数对 (p,q)(p, q)

  • 1p<qN1 \le p < q \le N
  • (xpxq)2+(ypyq)2K\sqrt{(x_p-x_q)^2+(y_p-y_q)^2} \le K

这里保证满足条件的整数对最多有 4×1054 \times 10^5 对。

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

Problem Statement

Given are NN pairs of integers (xi,yi)(x_i,y_i), numbered 11 to NN, and an integer KK.
List all pairs of integers (p,q)(p,q) that satisfy the conditions below, in the format specified in Output.

  • 1p<qN1 \le p < q \le N
  • (xpxq)2+(ypyq)2K\sqrt{(x_p-x_q)^2+(y_p-y_q)^2} \le K

Here, it is guaranteed that there are at most 4×1054 \times 10^5 such pairs of integers.

Constraints

  • All values in input are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1K1.5×1091 \le K \le 1.5 \times 10^9
  • 0xi,yi1090 \le x_i,y_i \le 10^9
  • There are at most 4×1054 \times 10^5 pairs of integers that should be listed.

Input

Input is given from Standard Input in the following format:

NN KK

x1x_1 y1y_1

x2x_2 y2y_2

\vdots

xNx_N yNy_N

Output

Print the answer in the following format.

MM

p1p_1 q1q_1

p2p_2 q2q_2

\vdots

pMp_M qMq_M

The first line should contain an integer MM, representing the number of pairs of integers to be listed.

The subsequent MM lines should contain the pairs of integers to be listed (pi,qi)(p_i,q_i) in lexicographical order, each in its own line, separated by a space.

Here, a pair of integers (a,b)(a,b) comes before a pair of integers (c,d)(c,d) if and only if one of the following conditions is satisfied.

  • a<ca<c.

  • a=ca=c and b<db<d.

Sample Input 1

6 5
2 0
2 2
3 4
0 0
5 5
8 3

Sample Output 1

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

There are 99 pairs of integers that satisfy the conditions, which should be printed in the specified format.
$(1,2),(1,3),(1,4),(2,3),(2,4),(2,5),(3,4),(3,5),(5,6)$

Sample Input 2

2 1414213562
0 0
1000000000 1000000000

Sample Output 2

0

There may be zero pairs of integers that satisfy the conditions.

Sample Input 3

10 150
300 300
300 400
300 500
400 300
400 400
400 400
400 500
500 300
500 400
500 500

Sample Output 3

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

There may be pairs of integers (i,j)(i,j) (i<ji < j) such that xi=xjx_i=x_j and yi=yjy_i=y_j.

update @ 2024/3/10 10:10:59