백준 10816 - 숫자 카드 2 (파이썬)
Updated:
Answer
import sys
N = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
M = int(sys.stdin.readline())
b = list(map(int, sys.stdin.readline().split()))
a.sort()
def solution(n, s, e):
if s > e:
return 0
m = (s + e) // 2
if a[m] == n:
return a[s:e + 1].count(n)
elif a[m] < n:
return solution(n, m + 1, e)
else:
return solution(n, s, m - 1)
c = {}
for n in b:
if n not in c:
c[n] = solution(n, 0, N - 1)
print(' '.join(str(c[x]) for x in b))