AcWing 789. 数的范围 python
原题链接
简单
作者:
申侠
,
2021-03-05 10:13:37
,
所有人可见
,
阅读 266
n, m = map(int, input().split())
lt = list(map(int, input().split()))
def lowerBound(lt, l, r, k):
while l < r:
mid = l + (r-l) // 2
if lt[mid] < k: l = mid + 1
else: r = mid
return r
def upperBound(lt, l, r, k):
while l < r:
mid = l + (r-l) // 2
if lt[mid] <= k: l = mid + 1
else: r = mid
return r
for i in range(m):
k = int(input())
upper = upperBound(lt, 0, n, k) - 1
lower = lowerBound(lt, 0, n, k)
if lower < n and upper < n and lt[lower] == lt[upper] == k:
print(f'{lower} {upper}')
else:
print('-1 -1')