I am trying to find number of elements smaller than or equal to a particular value inside the multiset. I want a logn time approach. I have tried using distance(s.begin(),s.upper_bound(val)). But using distance method could take O(N) time in worst case.Can someone help me.