algo

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub kuhaku-space/algo

:heavy_check_mark: めぐる式二分探索 (lib/algorithm/binary_search.hpp)

Verified with

Code

#pragma once
#include <cmath>
#include <cstdint>
#include <numeric>

/// @brief めぐる式二分探索
template <class T, class F>
T meguru_binary_search(T ok, T ng, F check) {
    while (std::abs(ok - ng) > 1) {
        T mid = std::midpoint(ok, ng);
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "lib/algorithm/binary_search.hpp"
#include <cmath>
#include <cstdint>
#include <numeric>

/// @brief めぐる式二分探索
template <class T, class F>
T meguru_binary_search(T ok, T ng, F check) {
    while (std::abs(ok - ng) > 1) {
        T mid = std::midpoint(ok, ng);
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}
Back to top page