algorithm

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

View the Project on GitHub gtnao/algorithm

:heavy_check_mark: src/search/binary_search.hpp

Verified with

Code

#pragma once

#include <bits/stdc++.h>
using namespace std;

template <typename T> T bin_search(T ng, T ok, function<bool(T)> is_ok) {
  while (abs(ok - ng) > 1) {
    T mid = (ok + ng) / 2;

    if (is_ok(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}
#line 2 "src/search/binary_search.hpp"

#include <bits/stdc++.h>
using namespace std;

template <typename T> T bin_search(T ng, T ok, function<bool(T)> is_ok) {
  while (abs(ok - ng) > 1) {
    T mid = (ok + ng) / 2;

    if (is_ok(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}
Back to top page