#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define loop(i,n) sloop(0,i,n) #define sloop(s, i, n) for(ll i=(s);i<(n);i++) #define rloop(i,n) rsloop(0,i,n) #define rsloop(s,i,n) for(ll i=(n);i-->(s);) #define all(v) (v).begin(),(v).end() #ifdef DEBUG #define DBG cout << __LINE__ << endl; #else #define DBG #endif //int xses[8] = {-1,1,0,0,-1,1,1,-1}; //int yses[8] = {0,0,-1,1,-1,1,-1,1}; #define int ll const int N = 50'007; void solve() { int n,m,q; cin >> n >> m >> q; vector<bitset<N>> v(n+m); loop(i,n) { for(int j = i+1; j<=n; j+=i+1) { v[i][j] = 1; } } sloop(n,i,m+n) { int t,x,y; cin >> t >> x; if(t!=3)cin >> y; if(t==1) { v[i] = v[x-1] | v[y-1]; }else if(t==2) { v[i] = v[x-1] & v[y-1]; }else{ v[i] = ~v[x-1]; } } /* loop(i,n+m) { sloop(1,j,n+1) { if(v[i][j])cout << j << ' '; } cout << endl; }*/ while(q--) { int a,b; cin >> a >> b; if(v[a-1][b])cout << "TAK\n"; else cout << "NIE\n"; } } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); solve(); 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define loop(i,n) sloop(0,i,n) #define sloop(s, i, n) for(ll i=(s);i<(n);i++) #define rloop(i,n) rsloop(0,i,n) #define rsloop(s,i,n) for(ll i=(n);i-->(s);) #define all(v) (v).begin(),(v).end() #ifdef DEBUG #define DBG cout << __LINE__ << endl; #else #define DBG #endif //int xses[8] = {-1,1,0,0,-1,1,1,-1}; //int yses[8] = {0,0,-1,1,-1,1,-1,1}; #define int ll const int N = 50'007; void solve() { int n,m,q; cin >> n >> m >> q; vector<bitset<N>> v(n+m); loop(i,n) { for(int j = i+1; j<=n; j+=i+1) { v[i][j] = 1; } } sloop(n,i,m+n) { int t,x,y; cin >> t >> x; if(t!=3)cin >> y; if(t==1) { v[i] = v[x-1] | v[y-1]; }else if(t==2) { v[i] = v[x-1] & v[y-1]; }else{ v[i] = ~v[x-1]; } } /* loop(i,n+m) { sloop(1,j,n+1) { if(v[i][j])cout << j << ' '; } cout << endl; }*/ while(q--) { int a,b; cin >> a >> b; if(v[a-1][b])cout << "TAK\n"; else cout << "NIE\n"; } } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); solve(); return 0; } |