CF765F.Souvenirs

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Artsem is on vacation and wants to buy souvenirs for his two teammates. There are nn souvenir shops along the street. In ii -th shop Artsem can buy one souvenir for aia_{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 mm times. For some strange reason on the ii -th day only shops with numbers from lil_{i} to rir_{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 asat|a_{s}-a_{t}| where li<=s,t<=ril_{i}<=s,t<=r_{i} , sts≠t .

输入格式

The first line contains an integer nn ( 2<=n<=1052<=n<=10^{5} ).

The second line contains nn space-separated integers a1a_{1} , ..., ana_{n} ( 0<=ai<=1090<=a_{i}<=10^{9} ).

The third line contains the number of queries mm ( 1<=m<=31051<=m<=3·10^{5} ).

Next mm lines describe the queries. ii -th of these lines contains two space-separated integers lil_{i} and rir_{i} denoting the range of shops working on ii -th day ( 1<=li<ri<=n1<=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
    
首页