#P9062. [Ynoi2002] Adaptive Hsearch&Lsearch

[Ynoi2002] Adaptive Hsearch&Lsearch

Problem Description

There are nn points p1,p2,,pnp_1,p_2,\dots,p_n on a two-dimensional plane.

There are qq queries. In the ii-th query, two numbers li,ril_i,r_i are given (1li<rin1\leq l_i< r_i\leq n). You need to find a pair (u,v)(u,v) such that liu<vril_i\leq u<v\leq r_i, and the Euclidean distance (xuxv)2+(yuyv)2\sqrt{(x_u-x_v)^2+(y_u-y_v)^2} between pup_u and pvp_v is minimized.

Input Format

The first line contains two integers n,qn,q, representing the number of points and the number of queries.

The next nn lines each contain two integers xi,yix_i,y_i, representing the coordinates of pip_i.

The next qq lines each contain two integers li,ril_i,r_i (1li<rin1\leq l_i< r_i\leq n), representing the ii-th query.

Output Format

For each query, output one integer per line, representing the minimum value of (xuxv)2+(yuyv)2(x_u-x_v)^2+(y_u-y_v)^2.

5 5
2 4
1 1
3 3
5 1
4 2
1 5
2 3
2 4
3 5
1 3
2
8
8
2
2
2 1
1 1
1 1
1 2
0

Hint

Idea: Claris, Solution: Claris, Code: Claris, Data: Claris & nzhtl1477.

For 100%100\% of the testdata, 2n2500002 \leq n\leq 250\,000, 1q2500001\leq q\leq 250\,000, 1xi,yi1081\leq x_i,y_i\leq 10^8.

Translated by ChatGPT 5