We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eff07d7 commit 2112907Copy full SHA for 2112907
jaykxo/week03/10816_숫자_카드_2.py
@@ -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