I have a sorted(according to first.second element)vector pair of following type : vector<pair<pair<int,int>,int>>p;
My Comparator function to sort vector pair
bool sortbysec(pair<pair<int,int>,int>&a,pair<pair<int,int>,int>&b) { if(a.first.second==b.first.second)return a.first.first<b.first.first; else return a.first.second<b.first.second; } I want upper bound of p.first.secondelement on the list of p.first.firstelements.
For example -
2 2 7 1 3 4 1 4 3 4 5 8 5 7 5 4 8 6 5 8 1 6 8 9 8 8 0 8 9 2 In simple words, I want an upper bound of middle element of the vector pair.Searching the upper bound of that particular element should be done in list of first element of the vector pair.
For Example, upper bound of 3 in second row is 4 in the 4th row.
My question is : I dont know how to code this thing. I have tried this syntax(incorrect):
auto it=lower_bound(v.begin(),v.end(),make_pair(make_pair(2,2),7)); This is showing error. I hope you understood the question. Please anyone tell me a way how to code it properly so i get the desired results in c++ only.
std::tuple<int, int, int>(orstd::array<int, 3>) instead ofpair<pair<int,int>,int>?lower_boundas the one you used for sorting, but atm I have honestly no clue what your error is#define int long long int. This is undefined behavior. You are lucky that you got a compiler error and not worse. Don't ever do that. If you want to declare a variable of typelong long intthen writelong long int x;because when you writeint x;you declare a variable of typeintnot of typelong long int(unless you break the language)