✔ 풀이를 위한 아이디어
✔ 코드
import sys
from collections import Counter
N = int(sys.stdin.readline())
own = list(map(int, sys.stdin.readline().split()))
cnt = sorted(Counter(own).most_common())
M = int(sys.stdin.readline())
quest = list(map(int, sys.stdin.readline().split()))
answer = []
for i in range(M):
end = len(cnt) - 1
start = 0
while True:
if start > end:
answer.append(0)
break
mid = (start + end) // 2
if cnt[mid][0] < quest[i]:
start = mid + 1
elif cnt[mid][0] > quest[i]:
end = mid - 1
elif cnt[mid][0] == quest[i]:
answer.append(cnt[mid][1])
break
for i in range(M):
print("{} ".format(answer[i]), end="")
print()
✔ 관련 개념