How to solve "most frequent" query?

Revision en1, by Absolut, 2016-06-29 03:04:22

How to solve the following problem? Given an array A of size N and M queries to solve. Each element in the array is less or equal than the size of the array.

N < 50000, M < 500000

Each query consist in two numbers l and r. We must answer what is the most frequent value (the one who appears more times) in the subarray A[l], A[l+1], ... , A[r-1], A[r]. If there are many posibilities answer the smallest.

Tags query, data structure, frequent

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Absolut 2016-06-29 03:04:22 449 Initial revision (published)