1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

lower_bound

Last updated at Posted at 2022-02-21

lower_bound(a+l, a+r, x) - a  (a は 小さい順にソートされている配列)

l≤i≤r−1 の中で、x≤ai となるような最小の i(ポインタ) の値を返す

計算量は O(log N)
ソートは O(N log N)

sort(a, a + N);
cout << lower_bound(a, a + N, x) - a << endl; //x以下の個数

ソート済みの配列に対して~以上の数が初めて現れる場所はlower_bound
ソート済みの配列に対して~より大きいの数が初めて現れる場所はupper_bound

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?