반응형
https://www.acmicpc.net/problem/10816
이진 탐색 라이브러리를 활용하여 문제를 풀이하였음.
import sys
from bisect import bisect_left, bisect_right
n = sys.stdin.readline()
a = sorted(list(map(int, sys.stdin.readline().split())))
m = sys.stdin.readline()
b = list(map(int, sys.stdin.readline().split()))
# 데이터의 개수를 반환하는 함수
def count_by_range(a, value):
right_index = bisect_right(a, value)
left_index = bisect_left(a, value)
return right_index - left_index
for i in b:
print(count_by_range(a, i), end=" ")
반응형
'알고리즘 풀이 > 이진 탐색' 카테고리의 다른 글
[백준/파이썬] [Silver V] 숫자 카드 - 10815 (0) | 2023.01.18 |
---|---|
[백준/파이썬] 1300번 : K번째 수 (0) | 2023.01.06 |
[Python] 이진 탐색 라이브러리 (0) | 2023.01.02 |
댓글