#P3901. Distinct Subarray Queries
Distinct Subarray Queries
Distinct Subarray Queries
You are given a sequence \(A_1, A_2, \ldots, A_N\) of integers and \(Q\) queries. Each query is represented by two integers \(L_i\) and \(R_i\). For each query, you need to check whether the subarray \(A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}\) contains all distinct elements.
More formally, for each query, determine if \[ \{A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}\}\n\] has a size equal to \(R_i - L_i + 1\). If it does, output Yes, otherwise output No.
inputFormat
The first line contains two integers \(N\) and \(Q\) denoting the number of elements in the sequence and the number of queries respectively.
The second line contains \(N\) space-separated integers \(A_1, A_2, \ldots, A_N\).
Each of the next \(Q\) lines contains two integers \(L_i\) and \(R_i\) representing a query.
outputFormat
For each query, output a single line containing Yes if all the elements in the subarray \(A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}\) are distinct, otherwise output No.
sample
5 3
1 2 3 2 1
1 3
2 4
1 5
Yes
No
No
</p>