편집 시간: 2022년 2월 7일 오후 9:04

코드

Algorithm/10816.py at main · Junroot/Algorithm

풀이

lower bound, upper bound 이진 탐색을 이용해서 각 숫자의 개수를 구했다.

다른 사람 풀이

해쉬맵을 이용한 방법도 있다.

from sys import stdin
_ = int(input())
n = [int(i) for i in stdin.readline().split()]
_ = int(input())
m = [int(i) for i in stdin.readline().split()]

hashmap = {}
for i in n:
    if i in hashmap:
        hashmap[i] += 1
    else:
        hashmap[i] = 1

print(' '.join(str(hashmap[i]) if i in hashmap else '0' for i in m))