https://www.acmicpc.net/problem/9375

나는 이 문제를 bisect를 통한 이분 탐색, 그리고 해시 맵을 사용해서 풀어봤다.
n = int(input())
nlist = list(map(int, input().split()))
nlist.sort()
m = int(input())
mlist = list(map(int, input().split()))
dictt = {}
for i in nlist:
if i in dictt:
dictt[i] += 1
else:
dictt[i] = 1
for i in mlist:
if i in dictt:
print(dictt[i], end=' ')
else:
print(0, end=' ')
from bisect import bisect_left, bisect_right
for i in mlist:
a = bisect_left(nlist, i)
b = bisect_right(nlist, i)
print(b - a, end = ' ')
bisect 는 같은 수가 여러 번 출력될 때 아주 유용한 듯하다. 같은 수가 몇 개 있는 지 궁금하면 bisect_right 에서 bisect_left 를 빼주면 된다.