PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000077. Khoảng cách giữa các phần tử bằng nhau (Closest Equals)
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ữa các phần tử bằng nhau (Closest Equals)
Closest Equals
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For each inclusive interval , find the minimum index distance between distinct indices in the range with equal array values; print -1 if no such pair exists.
Input
Read , signed integers and inclusive queries.
Output
Print the minimum distance or -1 for every query.
Subtasks
- Subtask 1 (10 points): , . ; .
- Subtask 2 (20 points): , . ; .
- Subtask 3 (25 points): , . ; .
- Subtask 4 (45 points): , . ; .
Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Explanation
Indices 1 and 2 in both contain 1, giving distance 1. Range has no repeated value. In , equal values 2 occur at indices 3 and 5, distance 2.