Skip to content

Instantly share code, notes, and snippets.

View raybbian's full-sized avatar

Raymond Bian raybbian

View GitHub Profile
// binary search
template <typename T, typename U> T last_true(T l, T r, U f) {
l--;
assert(l <= r);
while (l < r) {
T mid = l + (r - l + 1) / 2;
f(mid) ? l = mid : r = mid - 1;
}
return l;
}