C++ アルゴリズムとデータ構造のライブラリ
#include "library/search/binary_search/bi_ge_val.hpp"sort(A.begin(), A.end());
int v = bi_ge_val(A, x);
int v = bi_ge_val(st, x);
if (v == INF) {
// 値が存在しなかった
}
#pragma once
template <typename T> T bi_ge_val(vector<T> &v, const T &x) {
auto it = lower_bound(v.begin(), v.end(), x);
return (it == v.end() ? INF : *it);
}
template <typename T> T bi_ge_val(const set<T> &st, const T &x) {
auto it = st.lower_bound(x);
return (it == st.end() ? INF : *it);
}#line 2 "library/search/binary_search/bi_ge_val.hpp"
template <typename T> T bi_ge_val(vector<T> &v, const T &x) {
auto it = lower_bound(v.begin(), v.end(), x);
return (it == v.end() ? INF : *it);
}
template <typename T> T bi_ge_val(const set<T> &st, const T &x) {
auto it = st.lower_bound(x);
return (it == st.end() ? INF : *it);
}