#P4168. Dandelion Query
Dandelion Query
Dandelion Query
In the countryside, along the roadside, many dandelions are planted. For simplicity, we consider all dandelions as a sequence of length , given by $${a_1,a_2,\dots,a_n}$$, where each is a positive integer representing the species identifier of the -th dandelion.
For each query with an interval , you need to output the species that appears most frequently in that interval. If there are multiple species with the same frequency, output the one with the smallest identifier.
Note: Your algorithm must be online.
inputFormat
The first line contains an integer --- the number of dandelions. The second line contains positive integers . The third line contains an integer --- the number of queries. Each of the next lines contains two integers and , representing a query interval.
outputFormat
For each query, output the species identifier that appears most frequently within the interval on a new line. In case of a tie, output the smallest species identifier.
sample
5
1 1 2 2 3
3
1 5
1 2
4 5
1
1
2
</p>