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

constexpr int MAX = 50001;

using namespace std;
using BS = bitset<MAX>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, q, o, x, y, v;
    cin >> n >> m >> q;

    vector<BS> sets(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)
    {
        cin >> o;

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

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

        cout << (sets[x][v] ? "TAK\n" : "NIE\n");
    }

    return 0;
}