https://www.codetree.ai/missions/8/problems/point-on-the-line-segment/description
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
num = list(map(int, input().split()))
num.sort()
def lower_bound(target, num):
left = 0
right = len(num) -1
min_idx = len(num)
while left <= right:
mid = (left+right) //2
if num[mid] >= target:
min_idx = min(min_idx, mid)
right = mid -1
else:
left = mid + 1
return min_idx
def upper_bound(target, num):
left = 0
right = len(num) -1
min_idx = len(num)
while left <= right:
mid = (left+right) //2
if num[mid] > target:
min_idx = min(min_idx, mid)
right = mid -1
else:
left = mid + 1
return min_idx
for _ in range(m):
start, end = map(int, input().split())
print(upper_bound(end, num) - lower_bound(start, num),)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
---|---|
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 숫자의 개수 Python (0) | 2024.08.07 |
[Codetree] 빙빙 돌며 사각형 채우기 Python (0) | 2024.08.06 |