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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bitset>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 50001;
vector<bitset<MAX_N>> a;

bitset<MAX_N> set_union(const bitset<MAX_N>& s1, const bitset<MAX_N>& s2)
{
	return s1 | s2;  // Operacja sumy zbiorów bitowych (OR)
}

bitset<MAX_N> set_intersection(const bitset<MAX_N>& s1, const bitset<MAX_N>& s2)
{
	return s1 & s2;  // Operacja przecięcia zbiorów (AND)
}

bitset<MAX_N> set_negation(const bitset<MAX_N>& s, int limit)
{
	return ~s & bitset<MAX_N>().set();  // Negacja AND z maską ustawioną do `limit`
}

void process_operations(int n, int m)
{
	int i = n + 1;  // Indeks nowych zbiorów zaczyna się od n
	for (int j = 0; j < m; j++, i++)
	{
		int type, x, y;
		cin >> type >> x;
		if (type == 1)
		{  // Suma
			cin >> y;
			a[i] = set_union(a[x], a[y]);
		}
		else if (type == 2)
		{  // Przecięcie
			cin >> y;
			a[i] = set_intersection(a[x], a[y]);
		}
		else if (type == 3)
		{  // Negacja
			a[i] = set_negation(a[x], n);
		}
	}
}

void process_queries(int q)
{
	for (int i = 0; i < q; i++)
	{
		int x, v;
		cin >> x >> v;
		cout << (a[x].test(v) ? "TAK" : "NIE") << endl;
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	a.resize(n + m + 1);

	// Tworzenie początkowych zbiorów
	for (int j = 1; j <= n; j++)
	{
		int i = j;
		do {
			a[j].set(i);
			i += j;
		} while (i <= n);
	}

	process_operations(n, m);
	process_queries(q);

	return 0;
}