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
71
72
#include <cstdio>
#include <set>

using namespace std;

int main()
{
    int n,m,q;
    scanf("%d%d%d", &n, &m, &q);
    set<int> arr[n+m];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j <= n; j++){
            if(j%(i+1) == 0){
                arr[i].insert(j);
            }
        }
    }
    for(int i = 0; i < m; i++){
        int a, x, y;
        scanf("%d", &a);
        if(a != 3){
            scanf("%d%d", &x, &y);
            x--;
            y--;
        }
        else{
            scanf("%d", &x);
            x--;
        }
        if(a == 1){
            if(arr[x].size() < arr[y].size()){
                x += y;
                y = x - y;
                x = x - y;
            }
            arr[n + i] = arr[x];
            for(const auto& elem: arr[y]){
                arr[n+i].insert(elem);
            }
        }
        else if(a == 2){
            if(arr[x].size() > arr[y].size()){
                x += y;
                y = x - y;
                x = x - y;
            }
            for(const auto& elem : arr[x]){
                if(arr[y].count(elem) == 1){
                    arr[n+i].insert(elem);
                }
            }
        }
        else{
            for(int j = 1; j <= n; j++){
                if(arr[x].count(j) == 0){
                    arr[n+i].insert(j);
                }
            }
        }
    }
    for(int i = 0; i < q; i++){
        int x,v;
        scanf("%d%d", &x, &v);
        if(arr[x-1].count(v) == 1){
            printf("TAK\n");
        }
        else{
            printf("NIE\n");
        }
    }
    return 0;
}