Please read the new rule regarding the restriction on the use of AI tools. ×

vedprakashsingh216's blog

By vedprakashsingh216, history, 3 years ago, In English

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

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    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 years ago, # |
  Vote: I like it -10 Vote: I do not like it

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