import sys input_dane = sys.stdin.read() #input_dane = "50000 2 4\n1 50000 49000\n3 50001\n50001 49000\n7000 14000\n24999 49991\n50002 1" def zb1(text): lines = text.split('\n') n, m, q = map(int, lines[0].split()) tablice_poczatkowe = create(n) for i in range(1, m + 1): parts = list(map(int, lines[i].split())) if parts[0] == 1: tablice_poczatkowe.append(tablice_poczatkowe[parts[1] - 1] | tablice_poczatkowe[parts[2] - 1]) elif parts[0] == 2: tablice_poczatkowe.append(tablice_poczatkowe[parts[1] - 1] & tablice_poczatkowe[parts[2] - 1]) elif parts[0] == 3: tablice_poczatkowe.append(set(range(1, n + 1)) - tablice_poczatkowe[parts[1] - 1]) ans = [] for i in range(m + 1, m + q + 1): first_num, second_num = map(int, lines[i].split()) if second_num in tablice_poczatkowe[first_num - 1]: ans.append("TAK") else: ans.append("NIE") return "\n".join(ans) def create(n): tabl = [] for i in range(1, n + 1): if i > (n // 2) + 1: tabl.append({i}) else: tabl.append(set(range(i, n + 1, i))) return tabl print(zb1(input_dane))
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 | import sys input_dane = sys.stdin.read() #input_dane = "50000 2 4\n1 50000 49000\n3 50001\n50001 49000\n7000 14000\n24999 49991\n50002 1" def zb1(text): lines = text.split('\n') n, m, q = map(int, lines[0].split()) tablice_poczatkowe = create(n) for i in range(1, m + 1): parts = list(map(int, lines[i].split())) if parts[0] == 1: tablice_poczatkowe.append(tablice_poczatkowe[parts[1] - 1] | tablice_poczatkowe[parts[2] - 1]) elif parts[0] == 2: tablice_poczatkowe.append(tablice_poczatkowe[parts[1] - 1] & tablice_poczatkowe[parts[2] - 1]) elif parts[0] == 3: tablice_poczatkowe.append(set(range(1, n + 1)) - tablice_poczatkowe[parts[1] - 1]) ans = [] for i in range(m + 1, m + q + 1): first_num, second_num = map(int, lines[i].split()) if second_num in tablice_poczatkowe[first_num - 1]: ans.append("TAK") else: ans.append("NIE") return "\n".join(ans) def create(n): tabl = [] for i in range(1, n + 1): if i > (n // 2) + 1: tabl.append({i}) else: tabl.append(set(range(i, n + 1, i))) return tabl print(zb1(input_dane)) |