Frequent Values
Time limit1sMemory limit128 MB
For each range query on a sorted array, output how many times the most frequent value occurs inside the range.
- Level
Hard8 of 10
- Topics
- Segment tree, Divide and conquer, Array
- Solved
- No attempts yet
Problem
You are given a sequence of integers in non-decreasing order. You are also given several queries, each consisting of two indices and (). For each query, determine how many times the most frequent value occurs among .
Input
The input consists of several test cases. Each test case begins with a line containing two integers and (). The next line contains integers () separated by spaces. It is guaranteed that for every . The following lines each contain one query, given as two integers and () denoting the boundary indices of the query.
The last test case is followed by a line containing a single .
Output
For each query, print on its own line a single integer: the number of occurrences of the most frequent value within the given range.