pub fn binary_search<T, F>(f: F, ok: T, err: T) -> TExpand description
binary search for monotone segment
if ok < err then search [ok, err) where t(ok), t, t, …. t, t(ret), f, … f, f, f, err
if err < ok then search (err, ok] where err, f, f, f, … f, t(ret), … t, t, t(ok)
Examples found in repository?
More examples
crates/library_checker/src/number_theory/min_of_mod_of_linear.rs (lines 11-15)
6pub fn min_of_mod_of_linear(reader: impl Read, mut writer: impl Write) {
7 let s = read_all_unchecked(reader);
8 let mut scanner = Scanner::new(&s);
9 scan!(scanner, t, query: [(i64, u64, i64, i64)]);
10 for (n, m, a, b) in query.take(t) {
11 let x = binary_search(
12 |&x| floor_sum_range_freq(0, n, a, b, m, 0..x + 1) > 0,
13 m as i64 - 1,
14 -1,
15 );
16 writeln!(writer, "{}", x).ok();
17 }
18}