#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, q;
cin >> n >> m >> q;
vector<bitset<50001> > bs(450001);
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j += i) {
bs[i].set(j);
}
}
int a,b,c;
for (int i = 1; i <= m; i++) {
cin >> c;
if (c == 1) {
cin >> a >> b;
bs[n+i] = bs[a] | bs[b];
}
if (c == 2) {
cin >> a >> b;
bs[n+i] = bs[a] & bs[b];
}
if (c == 3) {
cin >> a;
bs[n+i] = ~bs[a];
}
}
int x,v;
for (int i = 1; i <= q; i++) {
cin >> x >> v;
if (bs[x].test(v)) {
cout << "TAK" << endl;
} else {
cout << "NIE" << endl;
}
}
return 0;
}
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 | #include <iostream> #include <vector> #include <bitset> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; vector<bitset<50001> > bs(450001); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { bs[i].set(j); } } int a,b,c; for (int i = 1; i <= m; i++) { cin >> c; if (c == 1) { cin >> a >> b; bs[n+i] = bs[a] | bs[b]; } if (c == 2) { cin >> a >> b; bs[n+i] = bs[a] & bs[b]; } if (c == 3) { cin >> a; bs[n+i] = ~bs[a]; } } int x,v; for (int i = 1; i <= q; i++) { cin >> x >> v; if (bs[x].test(v)) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } return 0; } |
English