Poklon
Time limit5sMemory limit512 MB
For each query interval, count distinct values that occur exactly twice within it. N and Q go up to 500,000.
- Level
Hard8 of 10
- Topics
- Prefix sum, Hash map, Segment tree
- Solved
- No attempts yet
Problem
Little Mirko is a very simple man. His friend Darko has given him an array of positive integers and asked him queries about the array, which Mirko must answer.
Each query consists of two integers: the positions of the left and right ends of an interval in the array. The answer to a query is the number of distinct values that appear exactly twice in the given interval.
Input
The first line contains the integers and ().
The second line contains positive integers, the elements of the array. Each of them is less than .
Each of the following lines contains two integers and () describing one query.
Output
Print lines. Line contains the answer to the -th query, in the order the queries are given.
Hint
In the first example, the interval from the first to the third element contains only one number (the number 1) that appears exactly twice.