I have a C++ set<int> s
, and an int a
which I know is in s
. Is there an O(log(size(s)))
way for me to figure out the number of elements of s
which are less than or equal to a
? I could use std::distance(s.begin(), s.find(a)) + 1
, but it takes O(size(s))
time.
Alternatively, does the STL provide a container that I can use for a set-like object that allows O(log(size(s)))
insertion, removal, and range length queries?