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

using namespace std;

//#define int long long

const int maxx = 50007;

vector<bitset<maxx+1>>secik;

signed main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, q;
    cin>>n>>m>>q;
    secik.resize(n+m+1);

    for(int i=1; n>=i; i++){
        for(int j = i; j <= n; j += i){
            secik[i].set(j);
        }
    }

    for(int i=n+1; n+m>=i; i++){
        int type, x, y;
        cin>>type;
        if(type == 1){
            cin>>x>>y;
            secik[i] = secik[x] | secik[y];
        }else if(type == 2){
            cin>>x>>y;
            secik[i] = secik[x] & secik[y];
        }else if(type == 3){
            cin>>x;
            secik[i] = ~secik[x];
            secik[i].reset(0);
        }
    }

    for(int i=0; q>i; i++){
        int x, v;
        cin>>x>>v;
        if(secik[x].test(v)){
            cout<<"TAK"<<endl;
        }
        else{
            cout<<"NIE"<<endl;
        }
    }
}