Skip to content

Commit 2112907

Browse files
committed
Solved: 10816 숫자 카드 2
1 parent eff07d7 commit 2112907

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 10816 숫자 카드 2
2+
# 메모리: 117520 KB, 시간: 1384 ms
3+
4+
5+
import bisect # 이분 탐색을 내장 함수로 제공
6+
import sys
7+
input = sys.stdin.readline
8+
9+
N = int(input())
10+
A = list(map(int, input().split()))
11+
A.sort() # 이분 탐색을 위한 정렬
12+
M = int(input())
13+
K = list(map(int, input().split()))
14+
15+
# bisect_left, bisect_right 내장 함수를 이용하여 구간(개수) 계산
16+
for t in K:
17+
left = bisect.bisect_left(A, t) # t가 처음 등장하는 인덱스
18+
right = bisect.bisect_right(A, t) # t가 마지막으로 끝난 뒤 인덱스
19+
count = (right - left) # 두 위치 차이가 t의 개수
20+
21+
print(count, end=" ") # 개수를 공백으로 구분하여 출력

0 commit comments

Comments
 (0)