def bisect_search_left(arr, target):
res = 0
left, right = 0, len(arr) - 1
while left <= right: # 重点
mid = (right + left) // 2
if arr[mid] >= target:
# target 在 mid 的左边
res = mid
right = mid - 1
else:
left = mid + 1
return res
def bisect_search_right(arr, target):
res = 0
left, right = 0, len(arr) - 1
while left <= right: # 重点
mid = (right + left) // 2
if arr[mid] <= target:
# target 在 mid 的右边
res = mid
left = mid + 1
else:
right = mid - 1
return res
a = [1,2,2,2,2,3,3,3,7,10]
print(bisect_search_left(a, 2))
print(bisect_search_right(a, 2))
print(bisect_search_left(a, 3))
print(bisect_search_right(a, 3))