New binary search method

Revision ru1, by ColobocCodeforces, 2024-12-04 13:37:13

There is new method of binary search which may be exist but I didn't see it.

Instead of using left and right, we can simply add new bit to our answer if it is possible:

while bit > 0:
   if check(ans + plus): 
      ans += plus
   plus /= 2

Constant will be much smaller.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru2 Russian ColobocCodeforces 2024-12-04 13:38:04 21
ru1 Russian ColobocCodeforces 2024-12-04 13:37:13 321 Первая редакция (опубликовано)