#C7854. Count Unique Elements in Subarray

    ID: 51771 Type: Default 1000ms 256MiB

Count Unique Elements in Subarray

Count Unique Elements in Subarray

You are given an array of N integers and Q queries. Each query is defined by two indices, L and R (0-indexed), and your task is to determine the number of unique elements in the subarray from index L to index R (inclusive).

Mathematically, for a query defined by indices \(L\) and \(R\), you are required to compute the following quantity:

[ |{a_i : L \leq i \leq R}|, ]

where \(|\cdot|\) denotes the cardinality of a set. The input guarantees that the indices are valid for the given array.

Your solution should read from standard input (stdin) and write the answers for each query to standard output (stdout), each on a new line.

inputFormat

The first line contains two integers N and Q, where N is the number of elements in the array and Q is the number of queries to process.

The second line contains N space-separated integers representing the array elements.

The next Q lines each contain two integers L and R (0-indexed), representing a query asking for the number of unique integers in the subarray from index L to index R (inclusive).

outputFormat

For each query, output the number of unique integers in the specified subarray. Each result should be printed on a new line.

## sample
5 2
1 2 1 3 2
0 2
1 4
2

3

</p>