백준 2776 암기왕

highway92·2021년 10월 11일
0

백준

목록 보기
22/27

문제출처 : https://www.acmicpc.net/problem/2776

풀이과정

  1. 입력을 받은 후 note1을 정렬해준다.

  2. note2에 대하여 이분탐색을 수행한다.

import sys

input = sys.stdin.readline

t = int(input())

def search(s,e,note1, target):
    while s<=e:
        mid = (s+e) // 2

        if note1[mid] == target:
            return 1
        elif note1[mid] < target:
            s = mid + 1
        else:
            e = mid -1
    
    return 0
    


def solve():
    n = int(input())
    note1 = list(map(int,input().split()))
    m=int(input())
    note2 = list(map(int,input().split()))
    note1.sort()
    
    for i in note2:
        print(search(0,n-1,note1,i))

for _ in range(t):
    solve()


profile
웹 개발자로 활동하고 있습니다.

0개의 댓글