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
#include <iostream>
#include <unordered_set>
using namespace std;
const int N=50001;
const int M=400001;
unordered_set<int>v[N];
int operacje[M];
pair<int,int> tab[M];
bool czyzawiera(int x,int k,int n){
    if(x<=n){
        if(v[x].find(k)!=v[x].end()){
            return 1;
        }else{
            return 0;
        }
    }else{
        if(operacje[x-n]==1){
            return (czyzawiera(tab[x-n].first,k,n)||czyzawiera(tab[x-n].second,k,n));
        }
        if(operacje[x-n]==2){
            return (czyzawiera(tab[x-n].first,k,n)&&czyzawiera(tab[x-n].second,k,n));
        }
        if(operacje[x-n]==3){
            return (!czyzawiera(tab[x-n].first,k,n));
        }
    }
}
int main()
{
    cin.tie();
    cout.tie();
    ios_base::sync_with_stdio(0);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++){
        v[i].insert(i);
        for(int j=i*2;j<=n;j+=i){
            v[i].insert(j);
        }
    }
    for(int i=1;i<=m;i++){
        int a;
        cin>>a;
        operacje[i]=a;
        if(a==1||a==2){
            int b,c;
            cin>>b>>c;
            tab[i]={b,c};
        }
        if(a==3){
            int b;
            cin>>b;
            tab[i]={b,0};
        }
    }
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        if(czyzawiera(a,b,n)){
            cout<<"TAK\n";
        }else{
            cout<<"NIE\n";
        }
    }
    return 0;
}