Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя vedprakashsingh216

Автор vedprakashsingh216, история, 3 года назад, По-английски

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

  • Проголосовать: нравится
  • -20
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can't we use lower bound on vector of pairs of type long long int? it's not working for me.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    Here we have to type cast the argruments we send in lower refer to the code below

    vector<pair<ll,ll>> vp;
        vp.push_back({3,6});
        vp.push_back({3,4});
        vp.push_back({4,5});
        vp.push_back({4,2});
        vp.push_back({7,4});
        vp.push_back({8,5});
        //cout<<numeric_limits<ll>::max()<<"\n";
        auto it = lower_bound(vp.begin(),vp.end(),make_pair((ll)5,numeric_limits<ll>::min()));    
        cout<<it->first<<" "<<it->second<<"\n";
    
»
3 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

This is his first post guys, please go easy on him. He is just trying to contribute to the community. You are doing good work, keep it up