Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
F
Souvenirs
Codeforces
3100
原题
← EG →
翻译中…

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*$.

翻译中…

Input

翻译中…

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*$).

翻译中…

Output

翻译中…

Print the answer to each query in a separate line.

翻译中…

样例

Input #1
8
3 1 4 1 5 9 2 6
4
1 8
1 3
4 8
5 7
Output #1
0
1
1
3
InputCopy OutputCopy
题目信息
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。