### meiniak's blog

By meiniak, history, 21 month(s) ago,

I got always confused on how to leviate in-built stl function to use upper and lower bound. For eg: in yesterday previous B question I wrote my own upperBound on vector pair.

I think mostly there are 3 variation:

lowerbound on pair with smallest index lowerbound on pair with largest index

upperbound pair with smallest index

Thanx codeforces

• +2

 » 21 month(s) ago, # |   0 I think you just can write your own comparator instead of your own upperbound. Some thing like this : Spoilerbool comparator1(const pair &a , const pair &b) { return a.first < b.first; }And use it after in the such way: Spoilerauto it = upper_bound({your array}.begin() , {your array}.end() , {your pair} , comparator1); Hope it helps.
•  » » 21 month(s) ago, # ^ |   0 getting compile time error submission
•  » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Fixed. Sorry about that. Spoilerans+=(vp.end() — upper_bound(all(vp),pair(vp[i].second , -1),cmp));
•  » » » » 21 month(s) ago, # ^ |   0 Got AC. 68235199
•  » » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Ok, why this work ? and in comparator we wrote the first argument which will be pass is the value on which we are performing upper bound right? And how can we write lower_bound comparator such that it return us least and greatest index. 0 1 2 3 4 5[{1,2}, {3,4}, {5,5}, {5,5}, {5,5}, {6,7}]On doing lower_bound on on pair 1'st value {4,something} i will get {5,5} as first occurence on index 2 and {5,5} index 4