#K4581. Minimum Range Query
Minimum Range Query
Minimum Range Query
You are given an array \(A\) of \(n\) integers and \(q\) queries. For each query you are given a target value. Your task is to find the smallest range (i.e. the first two occurrences) in \(A\) that contains the target value at least twice.
If the target value appears at least twice, output the indices of the first two occurrences (0-indexed). Otherwise, output -1 -1
.
Note: The range is defined by the indices \(i\) and \(j\) with \(i < j\), such that \(A[i] = A[j] = target\). In this problem, you only need to consider the very first pair for each target if it appears more than once.
Example: For \(A = [1, 2, 2, 3, 4, 5, 5, 5, 6, 6]\) and queries [2, 5, 9], the answers are:
- For target 2, the first two occurrences are at indices 1 and 2, so output
1 2
. - For target 5, the first two occurrences are at indices 5 and 6, so output
5 6
. - For target 9, it does not appear twice, so output
-1 -1
.
inputFormat
The first line contains two integers \(n\) and \(q\), representing the number of elements in the array and the number of queries respectively.
The second line contains \(n\) space-separated integers representing the array \(A\).
The third line contains \(q\) space-separated integers representing the queries.
outputFormat
For each query, output a line containing two space-separated integers. If the target value appears at least twice in the array, output the indices of its first two occurrences. Otherwise, output -1 -1
.
10 3
1 2 2 3 4 5 5 5 6 6
2 5 9
1 2
5 6
-1 -1
</p>