Colorful Village 2
InterviewTime limit2sMemory limit512 MB
For each query range in a nondecreasing brightness array, report how many times the most frequent value appears.
- Level
Medium6 of 10
- Topics
- Array, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
Minho looks after a country called Cheonnara, where there are houses. He numbered the houses 1 through .
One day Minho painted every house in the country. Each paint has its own brightness, and a careless order would spoil the look of the village, so he painted the houses so that the paint never gets darker as the house number grows. In other words, the brightness of house is at most the brightness of house .
Once the painting was done, Minho wanted to know how many times the most common brightness appears among the houses in a given range. Write a program that reports that count for every range he asks about.
Input
The first line contains the number of houses and the number of ranges , separated by a space. (, )
The second line contains the brightness values painted on houses 1 through , in order. (, and for every .)
Each of the next lines contains one range as two integers and (), meaning the houses from to .
Output
Print lines. On the -th line print how many times the most common brightness appears in the -th range.