CF1635F.Closest Pair

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn weighted points on the OXOX-axis. The coordinate and the weight of the ii-th point is xix_i and wiw_i, respectively. All points have distinct coordinates and positive weights. Also, xi<xi+1x_i \lt x_{i + 1} holds for any 1≤i<n1 \leq i \lt n.

The weighted distance between ii-th point and jj-th point is defined as ∣xi−xj∣⋅(wi+wj)|x_i - x_j| \cdot (w_i + w_j), where ∣val∣|val| denotes the absolute value of valval.

You should answer qq queries, where the ii-th query asks the following: Find the minimum weighted distance among all pairs of distinct points among the points in subarray [li,ri][l_i,r_i].

在 OXOX 轴上有 nn 个带权点。第 ii 个点的坐标和权重分别为 xix_i 和 wiw_i。所有点的坐标互不相同,且权重均为正数;此外,对任意 1≤i<n1 \leq i < n,均满足 xi<xi+1x_i < x_{i + 1}。

第 ii 个点与第 jj 个点之间的加权距离定义为 ∣xi−xj∣⋅(wi+wj)|x_i - x_j| \cdot (w_i + w_j),其中 ∣val∣|val| 表示 valval 的绝对值。

你需要回答 qq 个查询,其中第 ii 个查询要求:在子数组 [li,ri][l_i, r_i] 所包含的点中,求所有不同点对之间的最小加权距离。

输入格式

The first line contains 2 integers nn and qq (2≤n≤3⋅105;1≤q≤3⋅105)(2 \leq n \leq 3 \cdot 10^5; 1 \leq q \leq 3 \cdot 10^5) — the number of points and the number of queries.

Then, nn lines follows, the ii-th of them contains two integers xix_i and wiw_i (−109≤xi≤109;1≤wi≤109)(-10^9 \leq x_i \leq 10^9; 1 \leq w_i \leq 10^9) — the coordinate and the weight of the ii-th point.

It is guaranteed that the points are given in the increasing order of xx.

Then, qq lines follows, the ii-th of them contains two integers lil_i and rir_i (1≤li<ri≤n)(1 \leq l_i \lt r_i \leq n) — the given subarray of the ii-th query.

第一行包含两个整数 nn 和 qq(2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5;1≤q≤3⋅1051 \leq q \leq 3 \cdot 10^5)—— 分别表示点的数量和查询的数量。

接下来是 nn 行,其中第 ii 行包含两个整数 xix_i 和 wiw_i(−109≤xi≤109-10^9 \leq x_i \leq 10^9;1≤wi≤1091 \leq w_i \leq 10^9)—— 分别表示第 ii 个点的坐标和权重。

保证输入的点按 xx 坐标严格递增给出。

接下来是 qq 行,其中第 ii 行包含两个整数 lil_i 和 rir_i(1≤li<ri≤n1 \leq l_i \lt r_i \leq n)—— 表示第 ii 次查询所给定的子数组范围。

输出格式

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 11 and 33, which is equal to ∣x1−x3∣⋅(w1+w3)=∣−2−1∣⋅(2+1)=9|x_1 - x_3| \cdot (w_1 + w_3) = |-2 - 1| \cdot (2 + 1) = 9.

For the second query, the minimum weighted distance is between points 22 and 33, which is equal to ∣x2−x3∣⋅(w2+w3)=∣0−1∣⋅(10+1)=11|x_2 - x_3| \cdot (w_2 + w_3) = |0 - 1| \cdot (10 + 1) = 11.

For the fourth query, the minimum weighted distance is between points 33 and 44, which is equal to ∣x3−x4∣⋅(w3+w4)=∣1−9∣⋅(1+2)=24|x_3 - x_4| \cdot (w_3 + w_4) = |1 - 9| \cdot (1 + 2) = 24.

对于第一个查询,最小加权距离出现在点 11 和点 33 之间,其值为 ∣x1−x3∣⋅(w1+w3)=∣−2−1∣⋅(2+1)=9|x_1 - x_3| \cdot (w_1 + w_3) = |-2 - 1| \cdot (2 + 1) = 9。

对于第二个查询,最小加权距离出现在点 22 和点 33 之间,其值为 ∣x2−x3∣⋅(w2+w3)=∣0−1∣⋅(10+1)=11|x_2 - x_3| \cdot (w_2 + w_3) = |0 - 1| \cdot (10 + 1) = 11。

对于第四个查询,最小加权距离出现在点 33 和点 44 之间,其值为 ∣x3−x4∣⋅(w3+w4)=∣1−9∣⋅(1+2)=24|x_3 - x_4| \cdot (w_3 + w_4) = |1 - 9| \cdot (1 + 2) = 24。

输入解题思路,AI测评打分。不知道怎么写?

首页