CF765F.Souvenirs
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
阿尔特塞姆正在度假,想为他的两位队友购买纪念品。街道上共有 n 家纪念品商店。在第 i 家商店中,阿尔特塞姆可以以 ai 美元的价格购买一件纪念品,且每家商店最多只能购买一件纪念品。他不希望在团队中引发嫉妒心理,因此希望购买的两件纪念品价格之差尽可能小。
阿尔特塞姆共游览该购物街 m 次。出于某种奇怪的原因,在第 i 天,仅有编号从 li 到 ri 的商店营业(奇怪?确实如此;但你是否曾尝试为一个区间查询问题构思一个合理的背景故事呢?)。对于每次游览,阿尔特塞姆想知道:在当日营业的商店中,他所能购买的两件不同纪念品的最小可能价格差是多少。
换言之,对阿尔特塞姆的每次游览,你需要找出满足 li≤s,t≤ri 且 s=t 的所有下标对 (s,t) 中,∣as−at∣ 的最小可能值。
输入格式
The first line contains an integer n (2 ≤ n ≤ 105).
The second line contains n space-separated integers _a_1, ..., a__n (0 ≤ a__i ≤ 109).
The third line contains the number of queries m (1 ≤ m ≤ 3·105).
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).
第一行包含一个整数 n(2 ≤ n ≤ 105)。
第二行包含 n 个用空格分隔的整数 a1,…,an(0 ≤ ai ≤ 109)。
第三行包含查询次数 m(1 ≤ m ≤ 3⋅105)。
接下来的 m 行描述各个查询。其中第 i 行包含两个用空格分隔的整数 li 和 ri,表示第 i 天营业的商店区间(1 ≤ li < ri ≤ 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
输入解题思路,AI测评打分。不知道怎么写?