A10841 | Souvenirs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Artsem is on vacation and wants to buy souvenirs for his two teammates. There are $n$ souvenir shops along the street. In $i$ -th shop Artsem can buy one souvenir for $a_{i}$ dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price.
Artsem has visited the shopping street $m$ times. For some strange reason on the $i$ -th day only shops with numbers from $l_{i}$ to $r_{i}$ were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.
In other words, for each Artsem's visit you should find the minimum possible value of $|a_{s}-a_{t}|$ where $l_{i}<=s,t<=r_{i}$ , $s≠t$ .
Artsem has visited the shopping street $m$ times. For some strange reason on the $i$ -th day only shops with numbers from $l_{i}$ to $r_{i}$ were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.
In other words, for each Artsem's visit you should find the minimum possible value of $|a_{s}-a_{t}|$ where $l_{i}<=s,t<=r_{i}$ , $s≠t$ .
输入格式
The first line contains an integer $n$ ( $2<=n<=10^{5}$ ).
The second line contains $n$ space-separated integers $a_{1}$ , ..., $a_{n}$ ( $0<=a_{i}<=10^{9}$ ).
The third line contains the number of queries $m$ ( $1<=m<=3·10^{5}$ ).
Next $m$ lines describe the queries. $i$ -th of these lines contains two space-separated integers $l_{i}$ and $r_{i}$ denoting the range of shops working on $i$ -th day ( $1<=l_{i}<r_{i}<=n$ ).
The second line contains $n$ space-separated integers $a_{1}$ , ..., $a_{n}$ ( $0<=a_{i}<=10^{9}$ ).
The third line contains the number of queries $m$ ( $1<=m<=3·10^{5}$ ).
Next $m$ lines describe the queries. $i$ -th of these lines contains two space-separated integers $l_{i}$ and $r_{i}$ denoting the range of shops working on $i$ -th day ( $1<=l_{i}<r_{i}<=n$ ).
输出格式
Print the answer to each query in a separate line.
输入输出样例
输入 #1
8 3 1 4 1 5 9 2 6 4 1 8 1 3 4 8 5 7
输出 #1
0 1 1 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted