title: Data structure that supports range based most frequently occuring element query
body: <p>I'm looking for a data structure with which I can find the most frequently occuring number (among an array of numbers) in a given, variable range.</p>
  
  <p>Let's consider the following 1 based array:</p>
  
  <p>1 2 3 1 1 3 3 3 3 1 1 1 1</p>
  
  <p>If I query the range (1,4), the data structure must retun 1, which occurs twice.
  Several other examples:</p>
  
  <p>(1,13) = 1</p>
  
  <p>(4,9)  = 3</p>
  
  <p>(2,2)  = 2</p>
  
  <p>(1,3)  = 1 (all of 1,2,3 occur once, so return the first/smallest one. not so important at the moment)</p>
  
  <p>I have searched, but could not find anything similar. I'm looking (ideally) a data structure with minimal space requirement, fast preprocessing, and/or query complexities.</p>
  
  <p>Thanks in advance!</p>