meiniak's blog

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

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

 
 
 
 
  • Vote: I like it
  • +2
  • Vote: I do not like it

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

I think you just can write your own comparator instead of your own upperbound. Some thing like this :

Spoiler

And use it after in the such way:

Spoiler

Hope it helps.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    getting compile time error submission

    • »
      »
      »
      21 month(s) ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Fixed. Sorry about that.

      Spoiler
      • »
        »
        »
        »
        21 month(s) ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Got AC. 68235199

        • »
          »
          »
          »
          »
          21 month(s) ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          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