#C7552. Unique Subarray Query
Unique Subarray Query
Unique Subarray Query
You are given an array of n integers and q queries. Each query is represented by an integer k. For each query, determine whether the prefix subarray of length exactly \(k\) (i.e., the first \(k\) elements of the array) contains all unique elements. In other words, check if there are no repeated elements in the first \(k\) numbers.
Note: If \(k > n\), the answer should be NO
.
inputFormat
The first line contains two integers \(n\) and \(q\) separated by a space, representing the size of the array and the number of queries respectively. The second line contains \(n\) integers representing the array. The third line contains \(q\) integers, each denoting a query value \(k\).
Example:
6 3 1 2 3 1 4 5 3 4 2
outputFormat
For each query, output YES
if the first \(k\) elements of the array are unique; otherwise, output NO
. Each answer should be printed on a new line.
Example Output:
YES NO YES## sample
6 3
1 2 3 1 4 5
3 4 2
YES
NO
YES
</p>