serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 二分探索 配列中 以下の要素数
(library/search/binary_search/bi_le_cnt.hpp)

二分探索 配列中 以下の要素数

できること

計算量

$O(logN)$

使い方

sort(A.begin(), A.end());
int cnt = bi_le_cnt(A, x);

Verified with

Code

#pragma once
template <typename T> int bi_le_cnt(vector<T> &v, const T &x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin();
}
#line 2 "library/search/binary_search/bi_le_cnt.hpp"
template <typename T> int bi_le_cnt(vector<T> &v, const T &x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin();
}
Back to top page