import sys
import typing
def main():
undergoes_debugging: bool = len(sys.argv) > 1 and sys.argv[1] == "debugging"
input_stream: typing.IO = open("input.txt", "r") if undergoes_debugging else sys.stdin
solve(input_stream)
if undergoes_debugging:
input_stream.close()
def solve(input_stream: typing.IO) -> None:
n, m, q = map(int, input_stream.readline().split())
A = [None]
for i in range(1, n + 1):
A.append(frozenset(range(i, n + 1, i)))
domain = frozenset(range(1, n + 1))
for _ in range(m):
operation_type, *arguments = map(int, input_stream.readline().split())
match operation_type:
case 1:
A.append(A[arguments[0]] | A[arguments[1]])
case 2:
A.append(A[arguments[0]] & A[arguments[1]])
case 3:
A.append(domain - A[arguments[0]])
case _:
raise ValueError("illegal operation type:", operation_type)
for _ in range(q):
x, v = map(int, input_stream.readline().split())
ans = "TAK" if v in A[x] else "NIE"
print(ans)
if __name__ == '__main__':
main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import sys import typing def main(): undergoes_debugging: bool = len(sys.argv) > 1 and sys.argv[1] == "debugging" input_stream: typing.IO = open("input.txt", "r") if undergoes_debugging else sys.stdin solve(input_stream) if undergoes_debugging: input_stream.close() def solve(input_stream: typing.IO) -> None: n, m, q = map(int, input_stream.readline().split()) A = [None] for i in range(1, n + 1): A.append(frozenset(range(i, n + 1, i))) domain = frozenset(range(1, n + 1)) for _ in range(m): operation_type, *arguments = map(int, input_stream.readline().split()) match operation_type: case 1: A.append(A[arguments[0]] | A[arguments[1]]) case 2: A.append(A[arguments[0]] & A[arguments[1]]) case 3: A.append(domain - A[arguments[0]]) case _: raise ValueError("illegal operation type:", operation_type) for _ in range(q): x, v = map(int, input_stream.readline().split()) ans = "TAK" if v in A[x] else "NIE" print(ans) if __name__ == '__main__': main() |
English