Range Closest Pair of Points Query

아직 제출이 없습니다시간 제한9초메모리 제한1024 MB

문제

The closest pair of points problem is a well-known problem of computational geometry. In this problem, there are nn points p_1,p_2,,p_np\_1,p\_2,\ldots,p\_n in the Euclidean plane. You will be given qq queries. In the ii-th query, you will be given two integers _i\ell\_i and r_ir\_i (1_i<r_in1\leq \ell\_i< r\_i\leq n). You need to find a pair of points (u,v)(u,v) such that _iu\<vr_i\ell\_i\leq u\<v\leq r\_i and the Euclidean distance (x_ux_v)2+(y_uy_v)2\sqrt{(x\_u-x\_v)^2+(y\_u-y\_v)^2} between point p_up\_u and p_vp\_v is minimized.

입력

The first line of the input contains two integers nn and qq (2n250,0002 \leq n\leq 250\\,000, 1q250,0001\leq q\leq 250\\,000), denoting the number of points and the number of queries.

In the next nn lines, the ii-th line contains two integers x_ix\_i and y_iy\_i (1x_i,y_i1081\leq x\_i,y\_i\leq 10^8), describing the coordinates of p_ip\_i.

Each of the next qq lines contains two integers _i\ell\_i and r_ir\_i (1_i<r_in1\leq \ell\_i< r\_i\leq n), denoting a query.

출력

For each query, print a single line containing an integer, denoting the value of (x_ux_v)2+(y_uy_v)2(x\_u-x\_v)^2+(y\_u-y\_v)^2.