#K95272. Unique Integers in Subarrays

    ID: 38827 Type: Default 1000ms 256MiB

Unique Integers in Subarrays

Unique Integers in Subarrays

You are given an array of n integers. You are also given q queries. For each query, you are provided with two integers l and r representing the left and right indices (1-indexed) of a subarray. Your task is to determine the number of unique integers present in each subarray.

For each query, compute the value:

{ai:lir}\left|\{a_i : l \leq i \leq r\}\right|

where \(a_i\) denotes the element at index \(i\) in the array.

Read the input from stdin and output the results to stdout.

inputFormat

The first line contains two integers n and q separated by a space, where n is the number of elements in the array and q is the number of queries. The second line contains n integers representing the array elements. The following q lines each contain two integers l and r representing the bounds of the subarray (1-indexed).

outputFormat

For each query, output a single integer on a new line representing the count of unique integers in the subarray from index l to r.## sample

6 3
1 2 1 3 2 4
1 3
2 4
1 6
2

3 4

</p>