cp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ma-tw/cp-library

:x: algo/binary_search.hpp

Verified with

Code

#include <functional>

// binary search, finds the border of determ
template <typename T = long long, typename F>
T find_border(T ok, T ng, const F determ) {
    while (abs(ok - ng) > 1) {
        T mid = (ok + ng) / 2;
        if (determ(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}
#line 1 "algo/binary_search.hpp"
#include <functional>

// binary search, finds the border of determ
template <typename T = long long, typename F>
T find_border(T ok, T ng, const F determ) {
    while (abs(ok - ng) > 1) {
        T mid = (ok + ng) / 2;
        if (determ(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}
Back to top page