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
#include<bits/stdc++.h>
using namespace std;
constexpr int MAXN = 5e4+2;
bitset<MAXN> sets[2*MAXN];
int n, m, q;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m >> q;
  for(int i = 1; i <= n; ++i) {
    for(int j = i; j <= n; j += i) {
      sets[i][j] = 1;
    }
  } 

  for(int i = 1; i <= m; ++i) {
    int type{0};
    cin >> type;
    if(type == 1) {
      int a{0}, b{0};
      cin >> a >> b;
      sets[n+i] = sets[a] | sets[b];
    }
    else if(type == 2) {
      int a{0}, b{0};
      cin >> a >> b;
      sets[n+i] = sets[a] & sets[b];
    }
    else {
      int a{0};
      cin >> a;
      sets[n+i] = ~sets[a];
    }
  }

  for(int i = 1; i <= q; ++i) {
    int x{0}, v{0};
    cin >> x >> v;
    cout << (sets[x][v] ? "TAK\n" : "NIE\n");
  }

  /*
  for(int i = 1; i <= n+m; ++i) {
    cout << "ZBIOR " << i << ":";
    for(int j = 1; j <= n; ++j) if(sets[i][j]) cout << ' ' << j;
    cout << '\n';
  }*/

}