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

using namespace std;

vector<bitset<50001>> sets;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;

    sets.resize(n + m + 1);

    for (int i = 1; i <= n; ++i)
    {
        for (int j = i; j <= n; j += i)
            sets[i][j] = true;
    }

    for (int i = n + 1; i <= n + m; ++i)
    {
        int type, x, y;
        cin >> type;
        if (type == 1)
        {
            cin >> x >> y;
            sets[i] = sets[x] | sets[y];
        }
        else if (type == 2)
        {
            cin >> x >> y;
            sets[i] = sets[x] & sets[y];
        }
        else
        {
            cin >> x;
            sets[i] = ~sets[x];
        }
    }

    for (int i = 0; i < q; ++i)
    {
        int x, v;
        cin >> x >> v;
        if (sets[x][v]) cout << "TAK\n";
        else cout << "NIE\n";
    }
}