#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,q;
cin >> n >> m >> q;
vector<unordered_set<int>>zbiory(n+m);
for (int i=0;i<n;i++) {
for (int j=i;j<n;j+=(i+1)) {
zbiory[i].insert(j+1);
}
}
for (int i=0;i<m;i++) {
int t,x,y;
cin >> t >> x;
--x;
int ix=n+i;
if (t==1) {
cin >> y;
--y;
zbiory[ix] = zbiory[x];
zbiory[ix].insert(zbiory[y].begin(), zbiory[y].end());
}
else if (t==2) {
cin >> y;
--y;
for (int v:zbiory[x]) {
if(zbiory[y].count(v))
zbiory[ix].insert(v);
}
}
else if (t==3) {
for (int v=1;v<=n;v++) {
if (!zbiory[x].count(v))
zbiory[ix].insert(v);
}
}
}
for (int i=0;i<q;i++) {
int x, v;
cin >> x >> v;
--x;
if (zbiory[x].count(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 45 46 47 48 49 50 51 52 53 54 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m,q; cin >> n >> m >> q; vector<unordered_set<int>>zbiory(n+m); for (int i=0;i<n;i++) { for (int j=i;j<n;j+=(i+1)) { zbiory[i].insert(j+1); } } for (int i=0;i<m;i++) { int t,x,y; cin >> t >> x; --x; int ix=n+i; if (t==1) { cin >> y; --y; zbiory[ix] = zbiory[x]; zbiory[ix].insert(zbiory[y].begin(), zbiory[y].end()); } else if (t==2) { cin >> y; --y; for (int v:zbiory[x]) { if(zbiory[y].count(v)) zbiory[ix].insert(v); } } else if (t==3) { for (int v=1;v<=n;v++) { if (!zbiory[x].count(v)) zbiory[ix].insert(v); } } } for (int i=0;i<q;i++) { int x, v; cin >> x >> v; --x; if (zbiory[x].count(v)) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } return 0; } |
English