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
#include <bitset>
#include <iostream>
#include <vector>

constexpr int MAX = 50000;

using namespace std;

int main()
{
    int n, m, q, o, x, y, v;
    cin >> n >> m >> q;

    vector<bitset<MAX>> sets(n + m);

    sets[0].set();

    for (int j = 2; j <= n; ++j)
    {
        for (int i = j; i <= n; i += j)
        {
            sets[j - 1].set(i - 1);
        }
    }
    
    for (int j = 0; j < m; ++j)
    {
        cin >> o;

        if (o == 1)
        {
            cin >> x >> y;
            sets[n + j] = sets[x - 1] | sets[y - 1];
        }
        else if (o == 2)
        {
            cin >> x >> y;
            sets[n + j] = sets[x - 1] & sets[y - 1];
        }
        else
        {
            cin >> x;
            sets[n + j] = ~sets[x - 1];
        }
    }

    for (int i = 0; i < q; ++i)
    {
        cin >> x >> v;

        cout << (sets[x - 1].test(v - 1) ? "TAK" : "NIE") << endl;
    }

    return 0;
}