CF1635F.Closest Pair
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n weighted points on the OX -axis. The coordinate and the weight of the i -th point is xi and wi , respectively. All points have distinct coordinates and positive weights. Also, xi<xi+1 holds for any 1≤i<n .
The weighted distance between i -th point and j -th point is defined as ∣xi−xj∣⋅(wi+wj) , where ∣val∣ denotes the absolute value of val .
You should answer q queries, where the i -th query asks the following: Find the minimum weighted distance among all pairs of distinct points among the points in subarray [li,ri] .
输入格式
The first line contains 2 integers n and q (2≤n≤3⋅105;1≤q≤3⋅105) — the number of points and the number of queries.
Then, n lines follows, the i -th of them contains two integers xi and wi (−109≤xi≤109;1≤wi≤109) — the coordinate and the weight of the i -th point.
It is guaranteed that the points are given in the increasing order of x .
Then, q lines follows, the i -th of them contains two integers li and ri (1≤li<ri≤n) — the given subarray of the i -th query.
输出格式
For each query output one integer, the minimum weighted distance among all pair of distinct points in the given subarray.
输入输出样例
输入#1
5 5 -2 2 0 10 1 1 9 2 12 7 1 3 2 3 1 5 3 5 2 4
输出#1
9 11 9 24 11
说明/提示
For the first query, the minimum weighted distance is between points 1 and 3 , which is equal to ∣x1−x3∣⋅(w1+w3)=∣−2−1∣⋅(2+1)=9 .
For the second query, the minimum weighted distance is between points 2 and 3 , which is equal to ∣x2−x3∣⋅(w2+w3)=∣0−1∣⋅(10+1)=11 .
For the fourth query, the minimum weighted distance is between points 3 and 4 , which is equal to ∣x3−x4∣⋅(w3+w4)=∣1−9∣⋅(1+2)=24 .