p,q,r,s=open(0)
d={*q.split()}
print(*[+(i in d)for i in s.split()])
def solution():
import sys
A, B = sys.stdin.buffer.read().splitlines()[1::2]
A = set(A.split())
B = B.split()
print("".join("1 " if x in A else "0 " for x in B))
solution()
buffer.read()가 빠른가?
os.read
는 unbuffered read. 즉 필요한 만큼만 따온다.
sys.stdin.buffer.read()
는 buffered read. 버퍼를 사용하면 작은 양의 데이터를 여러번 읽어와야 할 때 os를 귀찮게 할 필요가 없다(reduce the number of syscalls made and thus operate with lower context-switch overhead when reading lots of data (in particular, when you would otherwise be doing lots of short reads, buffering reduces the number of round-trips between userland and the OS kernel)).
splitlines()
: String에 대한 메서드. 한 줄씩 끊어서 리턴한다(Returns a list of the lines in the string, breaking at line boundaries). 개행문자로도 끊기 때문에 strip할 필요가 없다. (keepend=True
일때는 개행문자 보존)
+(i in d)
: 불리언 값 앞에 + 기호로 숫자로 변환. True
-> 1, False
-> 0.