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
#include <bits/stdc++.h>
using namespace std;

typedef array<int, 2> pii;
typedef unsigned long long ull;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, m, q;
	cin >> n >> m >> q;

	vector<array<int, 3>> op;
	for (int i = 0; i < m; i++) {
		array<int, 3> v;
		cin >> v[0];
		if (v[0] == 1 || v[0] == 2) {
			cin >> v[1] >> v[2];
			--v[1]; --v[2];
		}
		else {
			cin >> v[1];
			--v[1];
		}
		op.push_back(v);
	}
	
	pii queries[q];
	for (auto &[x, y] : queries) {
		cin >> x >> y;
		--x; --y;
	}
	int ans[q];
	vector<int> bn[(n >> 6) + 1];
	for (int i = 0; i < q; i++) {
		auto [x, y] = queries[i];
		bn[y >> 6].push_back(i);
	}

	int b[n];
	for (int i = 0; i < n; i++) b[i] = i;
	for (int l = 0; l < n; l += 64) {
		int r = min(n, l + 64);
		ull a[n + m]{};
		for (int j = 0; j < n; j++) {
			while (b[j] < r) {
				a[j] |= (ull)1 << (b[j] - l);
				b[j] += j + 1;
			}
		}
		for (int j = n; j < n + m; j++) {
			auto v = op[j - n];
			if (v[0] == 1) {
				a[j] = a[v[1]] | a[v[2]];
			}
			if (v[0] == 2) {
				a[j] = a[v[1]] & a[v[2]];
			}
			if (v[0] == 3) {
				a[j] = ((ull)-1) ^ a[v[1]];
			}
		}
		for (int i : bn[l >> 6]) {
			auto [x, y] = queries[i];
			ans[i] = a[x] >> (y - l) & 1;
		}
	}
	for (int i = 0; i < q; i++) {
		cout << (ans[i] ? "TAK\n" : "NIE\n");
	}
}