#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 5e4 + 1;
const int MAXM = 4e5 + 1;
bitset<MAXN>* tab = new bitset<MAXN>[MAXM+MAXN];
bitset<MAXN> maska;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for(int i = 1; i <= n ; i++){
maska[i] = 1;
}
for(int i = 1; i <= n ; i++){
for(int j = i; j <= n ; j += i){
tab[i][j] = 1;
}
}
for(int i = n+1; i <= m+n ; i++){
int typ, x, y;
cin >> typ;
if(typ == 1){
cin >> x >> y;
tab[i] = tab[x]|tab[y];
}
else if(typ == 2){
cin >> x >> y;
tab[i] = tab[x]&tab[y];
}
else{
cin >> x;
tab[i] = (maska ^ tab[x]);
}
}
// for(int i = 1; i <= n+m ; i++){
// for(int j = 1; j <= n ; j++){
// cerr << tab[i][j];
// }
// cerr << "\n";
// }
while(q--){
int x, v;
cin >> x >> v;
if(tab[x][v]){
cout << "TAK\n";
}
else{
cout << "NIE\n";
}
}
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 55 56 57 58 59 60 61 62 63 | #include<bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 5e4 + 1; const int MAXM = 4e5 + 1; bitset<MAXN>* tab = new bitset<MAXN>[MAXM+MAXN]; bitset<MAXN> maska; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; for(int i = 1; i <= n ; i++){ maska[i] = 1; } for(int i = 1; i <= n ; i++){ for(int j = i; j <= n ; j += i){ tab[i][j] = 1; } } for(int i = n+1; i <= m+n ; i++){ int typ, x, y; cin >> typ; if(typ == 1){ cin >> x >> y; tab[i] = tab[x]|tab[y]; } else if(typ == 2){ cin >> x >> y; tab[i] = tab[x]&tab[y]; } else{ cin >> x; tab[i] = (maska ^ tab[x]); } } // for(int i = 1; i <= n+m ; i++){ // for(int j = 1; j <= n ; j++){ // cerr << tab[i][j]; // } // cerr << "\n"; // } while(q--){ int x, v; cin >> x >> v; if(tab[x][v]){ cout << "TAK\n"; } else{ cout << "NIE\n"; } } return 0; } |
English