I want to find no of elements present in set before the lower bound of an given element,I thought of using pointer arithmetic with std::set::iterators since they behave like pointer, here is what I tried:
set<int>q;
set<int>::iterator curr;
set<int>::iterator strt;
l = num.size();
q.insert(num[l-1]);
strt = q.begin();
temp = 1;
int x;
for(int i=l-2;i>=0;i--)
{
curr = q.lower_bound(num[i]);
if(curr == q.end())
stats.push_back({temp,0});
else
{
x = curr-strt;//ERROR
stats.push_back({x,temp-x});
}
q.insert(num[i]);
temp++;
}
is there is any way find no of elements present in set before the lower bound of an given element?