发布于2021-02-02
上次编辑2021-02-27
在区间上使用二分的前提是,当某个位置不满足条件时,那么所有比它小的位置(或者比它大的位置)都不满足条件。或者反过来说,当某个位置满足条件时,那么比它小的位置(或者比它大的位置)也都满足条件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
库函数
区间非降序排列。
C++
#include <algorithm>
pair 表示 lower_bound 和 upper_bound 分别搜索的结果Python
from bisect import bisect_left, bisect_right
lower_boundupper_bound