#C3441. Count Unique Symbols in Subarrays
Count Unique Symbols in Subarrays
Count Unique Symbols in Subarrays
You are given a sequence of integers representing symbols and a set of queries. For each query, specified by two indices \(l\) and \(r\) (using 0-based indexing), you must determine the number of unique symbols in the subarray from index \(l\) to index \(r\) (inclusive).
In other words, for a given sequence \(A\) of length \(n\) and a query \((l, r)\), you need to compute:
\[ \text{Answer} = \left|\{ A_i \mid l \leq i \leq r \}\right| \]This problem tests your understanding of basic array processing and subarray queries.
inputFormat
The input is given via standard input (stdin) with the following format:
- The first line contains two integers \(n\) and \(q\) where \(n\) is the length of the sequence and \(q\) is the number of queries.
- The second line contains \(n\) space-separated integers representing the sequence.
- Each of the next \(q\) lines contains two space-separated integers \(l\) and \(r\) (0-indexed) that represent a query.
outputFormat
For each query, output a single integer on a new line representing the number of unique symbols in the specified subarray.
## sample7 1
1 2 1 3 2 1 4
0 3
3
</p>