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

const int BITSET_SIZE = 50000;

int main() {
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);

    std::vector<std::bitset<BITSET_SIZE>> X(n + m + 1);
    for (int k=1; k<=n; ++k) {
        X[k].reset();
        for (int j=k; j<=n; j+=k) {
            X[k].set(j - 1);
        }
    }

    for (int i=0; i<m; ++i) {
        int a, x, y;
        scanf("%d", &a);
        if (a == 3) {
            scanf("%d", &x);
            X[n + i + 1] = ~X[x];
        } else {
            scanf("%d%d", &x, &y);
            if (a == 1) {
                X[n + i + 1] = X[x] | X[y];
            } else if (a == 2) {
                X[n + i + 1] = X[x] & X[y];
            }
        }
    }

    for (int k=0; k<q; ++k) {
        int x, v;
        scanf("%d%d", &x, &v);
        printf("%s\n", X[x].test(v-1) ? "TAK" : "NIE");
    }

    return 0;
}