Using lower_bound and upper bound on vector of pairs

Revision en1, by vedprakashsingh216, 2022-02-06 08:25:03

If you want to use lower bound or upper bound on vector of pairs then you may thing something of like this

lower_bound(vp.begin(),vp.end(),5);

But this is a wrong syntax as you need to pass a pair in the third argrument.

Now if use want to search from the first value of vector of pairs or use lower bound only on the first element and vice versa so :

In lower bound you may be saerching for the first element not less than the given value the following are the code for using lower bound

In lower bound

upper_bound(vp.begin(),vp.end(),make_pair(4,numeric_limits::max()) );

In upper bound

lower_bound(vp.begin(),vp.end(),make_pair(4,numeric_limits::min()) );

Ans vice versa if you want to use lower bound on the second value

this is my post upvote will be appriciated

Tags binary search, lower_bound, upper_bound, syntax, codeforces, help, education

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English vedprakashsingh216 2022-02-06 08:25:03 879 Initial revision (published)