• dichotomous search First place over k” is RIGHT, “first place over k” is LEFT python
>>> import bisect
>>> xs = [1, 2, 4, 4, 5]
>>> [bisect.bisect_left(xs, x) for x in range(7)]
[0, 0, 1, 2, 2, 4, 5]
>>> [bisect.bisect_right(xs, x) for x in range(7)]
[0, 1, 2, 2, 4, 5, 5]

image

atcoder


This page is auto-translated from /nishio/bisect using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I’m very happy to spread my thought to non-Japanese readers.