A14767 | Closest Pair
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ weighted points on the $OX$ -axis. The coordinate and the weight of the $i$ -th point is $x_i$ and $w_i$ , respectively. All points have distinct coordinates and positive weights. Also, $x_i < x_{i + 1}$ holds for any $1 \leq i < n$ .
The weighted distance between $i$ -th point and $j$ -th point is defined as $|x_i - x_j| \cdot (w_i + w_j)$ , 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 $[l_i,r_i]$ .
The weighted distance between $i$ -th point and $j$ -th point is defined as $|x_i - x_j| \cdot (w_i + w_j)$ , 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 $[l_i,r_i]$ .
输入格式
The first line contains 2 integers $n$ and $q$ $(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, $n$ lines follows, the $i$ -th of them contains two integers $x_i$ and $w_i$ $(-10^9 \leq x_i \leq 10^9; 1 \leq w_i \leq 10^9)$ — 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 $l_i$ and $r_i$ $(1 \leq l_i < r_i \leq n)$ — the given subarray of the $i$ -th query.
Then, $n$ lines follows, the $i$ -th of them contains two integers $x_i$ and $w_i$ $(-10^9 \leq x_i \leq 10^9; 1 \leq w_i \leq 10^9)$ — 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 $l_i$ and $r_i$ $(1 \leq l_i < r_i \leq 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 $|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 $2$ and $3$ , which is equal to $|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 $3$ and $4$ , which is equal to $|x_3 - x_4| \cdot (w_3 + w_4) = |1 - 9| \cdot (1 + 2) = 24$ .
For the second query, the minimum weighted distance is between points $2$ and $3$ , which is equal to $|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 $3$ and $4$ , which is equal to $|x_3 - x_4| \cdot (w_3 + w_4) = |1 - 9| \cdot (1 + 2) = 24$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted