PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000030. Khoảng cách giá trị nhỏ nhất trong đoạn (Minimum Distance)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Khoảng cách giá trị nhỏ nhất trong đoạn (Minimum Distance)
Minimum Distance
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an integer array . Each query specifies positions . Among all pairs , find the minimum value of . This is the distance between array values, not between their positions. Two equal values in the range imply an answer of zero.
Input
The first line is , followed by the array on the next line. Then comes , followed by query lines .
Output
For each query, print the smallest absolute difference between two values in the specified interval.
Subtasks
- Subtask 1 (10 points): ; ; ; . Every queried range contains at least two elements.
- Subtask 2 (20 points): ; ; ; . Every queried range contains at least two elements.
- Subtask 3 (30 points): ; ; ; . Every queried range contains at least two elements.
- Subtask 4 (40 points): ; ; ; . Every queried range contains at least two elements.
Examples
Input
8
3 1 4 1 5 9 2 6
4
1 8
1 3
4 8
5 7
Output
0
1
1
3
Explanation
Range has two ones, so the result is zero. Range contains , with minimum difference . Range contains , whose minimum difference is .