Reminder: in case of any technical issues, you can use the lightweight website m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

anajin's blog

By anajin, 5 years ago, In English,

I search it in google , but i can't find it. Can somebody tell me how to use lower_bound in set<pair<int,int>> , so i can find the fist pair whose first element is not small than the element i search for ?

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

»
5 years ago, # |
  Vote: I like it +35 Vote: I do not like it

x.lower_bound({first, -inf});

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    got it! Thanks.

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

    Could you explain the reasoning behind using that ? Also could you tell how you would do it for upper_bound ? Thanks :)

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

      x.upper_bound({first, inf});

    • »
      »
      »
      22 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      In these implementations we only care about the first value.

      pair<int,int> will compare the first int first, then the second int. We want ALL second integers to work

      As for upperbound Na2a uses {first, inf} because we want the value to be greater than first, and {first, inf} is the highest pair with first as its first value. (again, we only care about the first value)

  • »
    »
    16 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How to get the index of that pair,i mean we can't do this:x.lower_bound({first,-inf})-x.begin()?

  • »
    »
    4 months ago, # ^ |
    Rev. 2   Vote: I like it -48 Vote: I do not like it

    ok

  • »
    »
    4 months ago, # ^ |
      Vote: I like it -23 Vote: I do not like it

    IS INF IS INT_MAX???

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      INF is I think just a variable name, and its usually 1e18 , also you need to use long long to initialize it.

»
5 years ago, # |
  Vote: I like it -18 Vote: I do not like it

This is a pretty good site : http://bit.ly/1DMMnub