


비어있는 공집합 S가 주어졌을 때, 아래 연산을 수행하는 프로그램을 작성하시오.
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다.
둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
check 연산이 주어질때마다, 결과를 출력한다.
어떤 수가 존재하는지를 0 or 1로 기록하는 s 배열을 사용하여 어떤 수가 추가되면 1로, 삭제되면 0으로 저장하여 집합에 그 수가 존재하는지 in을 사용하지 않고도 바로 찾을 수 있다.
s = [0 for _ in range(21)]
import sys
input = sys.stdin.readline
n = int(input())
s = [0 for _ in range(21)]
for _ in range(n):
command = list(input().split())
if command[0] == 'add':
s[int(command[1])] = 1
elif command[0] == 'remove':
s[int(command[1])] = 0
elif command[0] == 'check':
print(s[int(command[1])])
elif command[0] == 'toggle':
s[int(command[1])] = 0 if s[int(command[1])] else 1
elif command[0] == 'all':
s = [1 for _ in range(21)]
elif command[0] == 'empty':
s = [0 for _ in range(21)]
존재여부만 기록할 수 있도록 하는 방법을 떠올린다면 쉽게 해결할 수 있는 문제.
https://www.acmicpc.net/problem/11723