I need to insert an element into sorted range, but I also need to know its index (number of elements in range that are less then the element). I want to do this in O(logN) time. Can I do this with basic C++ containers?
I was thinking to use std::multimap, with this container I can insert the element into its place with O(logN) complexity. But to get the index, I need to call std::distance, which takes O(N) operations, since multimap iterator is not random access.
Another way is to use sorted std::vector and std::binary_search algorithm. In this case the search takes O(logN), but the insertion will take O(N) operations, since the insertion to the middle of vector is linear operation.
So, is there std/boost container that I can use to reach the result, or I need to implement my own struct for this? Thanks!