Distinct values in a range
Time limit2sMemory limit512 MB
Given a static array and many range queries, report how many distinct values occur in each subarray.
- Level
Medium7 of 10
- Topics
- Array, Sorting, Prefix sum, Binary search
- Solved
- No attempts yet
Problem
A sequence of length is given. Write a program that answers queries on this sequence.
i j: report how many distinct numbers appear among .
A value that appears several times inside the range counts once.
Input
The first line contains the size of the sequence, . ()
The second line contains , separated by spaces. ()
The third line contains the number of queries, . ()
Each of the next lines holds one query as two integers and . ()
Output
For each query, print the number of distinct values in the range on its own line, in the order the queries are given.