Created
February 20, 2021 11:55
-
-
Save ashiato45/4c7bd3b83709da5ddf50647833f6f088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod nibutan{ | |
// bとuはinclusive | |
pub fn true_false(b: i64, u: i64, f: &dyn Fn(i64)->bool) -> (Option<i64>, Option<i64>){ | |
assert!(b <= u); | |
if f(b) == false{ | |
return (None, Some(b)); | |
} | |
if f(u) == true{ | |
return (Some(u), None); | |
} | |
// f(b) = trueかつf(u) = false | |
let mut b = b; | |
let mut u = u; | |
while (u - b).abs() > 1{ | |
let mid = (u + b)/2; | |
if f(mid){ | |
b = mid; | |
}else{ | |
u = mid; | |
} | |
} | |
return (Some(b), Some(u)); | |
} | |
pub fn false_true(b: i64, u: i64, f: &dyn Fn(i64)->bool) -> (Option<i64>, Option<i64>){ | |
return true_false(b, u, &|i|{!f(i)}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment