Working of lower_bound and upper_bound functions in set < pair < int , int > >

Правка en1, от sidforces, 2020-04-09 16:04:08

Can anyone explains me how the lower_bound and upper_bound functions work in set<pair<int,int> >. I mean to ask how they actually match any pair in the set with the given parameters step by step. Like i read somewhere that it first checks the first int and then goes for second so, what it actually does? Like I write this code-

set<pii> ms;

for(int i=0;i<10;i=i+2)

ms.insert(mp(i,i+1));

ms.insert(mp(2,4));

ms.insert(mp(2,2));

ms.insert(mp(4,4));

int x,y;

cin>>x>>y;

cout<<ms.lower_bound(mp(x,y))->first<<" "<<ms.lower_bound(mp(x,y))->second<<endl;

cout<<ms.upper_bound(mp(x,y))->first<<" "<<ms.upper_bound(mp(x,y))->second<<endl;

and on the input of (2,2) it is giving the output (2,2) for lowerbound and (2,3) for upperbound then why it is giving the output for upperbound as (2,3) because upperbound gives the just > value and it checks first int first then all pairs with '2' as first element should be discarded.And on the input of (7,10) output is (8,9) for both the functions. Now it is just checking the first int and ignoring the second int '10' because upperbound of 10 cannot be 9.

So, please if anybody can clear my confusions then please comment and may be I am understanding it totally wrong and asking the wrong question so please inlight me where i am wrong.

Thanks in advance.

Теги #set, lower_bound, upper_bound, pair

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский sidforces 2020-04-09 16:07:32 100
en1 Английский sidforces 2020-04-09 16:04:08 1463 Initial revision (published)