ContinueLib

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

View the Project on GitHub Continue765/ContinueLib

:heavy_check_mark: misc/binary_search.hpp

Depends on

Verified with

Code

#pragma once
#include <common.hpp>

template <typename T, typename F>
T firstTrue(T lo, T hi, F&& pred) {
    while (lo < hi) {
        T mid = midpoint(lo, hi);
        if (pred(mid)) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    return lo;
}

template <typename T, typename F>
T lastTrue(T lo, T hi, F&& pred) {
    while (lo < hi) {
        T mid = midpoint(hi, lo);
        if (pred(mid)) {
            lo = mid;
        } else {
            hi = mid - 1;
        }
    }
    return lo;
}
Back to top page