title: What data structure to find number of elements in a given range in O(log n) time?
body: <p>I'm solving a problem and I realized I am need of a data structure with following properties but cant find one even after few hours of googling. I believe STL library is too rich to not have this one hence asking here.</p>
  
  <ol>
  <li>Insert any element(should be able to contain repetetive ones) in <code>O(log(n))</code> time</li>
  <li>Remove an element in <code>O(log(n))</code> time as well.</li>
  <li>If i want to query for the number of elemenes in range [a,b], I
  should get that count in <code>O(log(n))</code> time..</li>
  </ol>
  
  <p>If I were to write it from scratch, for part 1 and 2, I would use a <code>set</code> or <code>multiset</code> and I would modify their <code>find()</code> method(which runs in <code>O(log(N))</code> time) to return indices instead of iterators so that I can do 
  <code>abs(find(a)-find(b))</code> so I get the count of elements in log(N) time. But unfortunately for me, <code>find()</code> returns and iterator.</p>
  
  <p>I have looked into <code>multiset()</code> and I could not accomplish requirement 3 in <code>O(log(n))</code> time. It takes <code>O(n)</code>. </p>
  
  <p>Any hints to get it done easily?</p>