// Karol Kosinski 2025 #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define X first #define Y second #define endl '\n' #define NAM(x) #x,'=',x using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; template<class...T> void _cout(T...a){(cout<<...<<a);} #ifndef ENABLE_DEBUG #define DEB(k,p,f,x...) #else #define DEB(k,p,f,x...) {if(k)_cout("------",setw(4),__LINE__," : ",__FUNCTION__,endl);if(p)f(x);} #endif #define DEBF(f,x...) DEB(1,1,f,x) #define DEBL DEBF(void,0) #define DEBC(p,x...) DEB(0,p,_cout,x) #define DEBUG(x...) DEBC(1,x) constexpr int NX = 50'001; constexpr int MX = 400'001; constexpr int BITS = NX / 64 + 1; int n, m, q, n64; ULL A[ NX + MX ][594]; void add(int ind) { int x, y; cin >> x >> y; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; const auto& U = A[y]; FOR(i,0,n64) S[i] = T[i] | U[i]; } void mul(int ind) { int x, y; cin >> x >> y; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; const auto& U = A[y]; FOR(i,0,n64) S[i] = T[i] & U[i]; } void neg(int ind) { int x; cin >> x; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; FOR(i,0,n64) S[i] = ~ T[i]; } void solve() { cin >> n >> m >> q; n64 = n / 64 + 1; FR_(i,1,n) { auto& S = A[i]; // S = new ULL[n64]; for ( int j = i; j <= n; j += i ) S[ j / 64 ] |= 1 << ( j % 64 ); } FR_( i, n + 1, n + m ) { int c; cin >> c; switch (c) { case 1 : add(i); break; case 2 : mul(i); break; default: neg(i); } } FOR(_,0,q) { int x, v; cin >> x >> v; if ( A[x][ v / 64 ] & ( 1 << ( v % 64 ) ) ) cout << "TAK\n"; else cout << "NIE\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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 97 98 99 100 101 102 103 104 105 106 107 | // Karol Kosinski 2025 #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define X first #define Y second #define endl '\n' #define NAM(x) #x,'=',x using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; template<class...T> void _cout(T...a){(cout<<...<<a);} #ifndef ENABLE_DEBUG #define DEB(k,p,f,x...) #else #define DEB(k,p,f,x...) {if(k)_cout("------",setw(4),__LINE__," : ",__FUNCTION__,endl);if(p)f(x);} #endif #define DEBF(f,x...) DEB(1,1,f,x) #define DEBL DEBF(void,0) #define DEBC(p,x...) DEB(0,p,_cout,x) #define DEBUG(x...) DEBC(1,x) constexpr int NX = 50'001; constexpr int MX = 400'001; constexpr int BITS = NX / 64 + 1; int n, m, q, n64; ULL A[ NX + MX ][594]; void add(int ind) { int x, y; cin >> x >> y; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; const auto& U = A[y]; FOR(i,0,n64) S[i] = T[i] | U[i]; } void mul(int ind) { int x, y; cin >> x >> y; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; const auto& U = A[y]; FOR(i,0,n64) S[i] = T[i] & U[i]; } void neg(int ind) { int x; cin >> x; auto& S = A[ind]; // S = new ULL[n64]; const auto& T = A[x]; FOR(i,0,n64) S[i] = ~ T[i]; } void solve() { cin >> n >> m >> q; n64 = n / 64 + 1; FR_(i,1,n) { auto& S = A[i]; // S = new ULL[n64]; for ( int j = i; j <= n; j += i ) S[ j / 64 ] |= 1 << ( j % 64 ); } FR_( i, n + 1, n + m ) { int c; cin >> c; switch (c) { case 1 : add(i); break; case 2 : mul(i); break; default: neg(i); } } FOR(_,0,q) { int x, v; cin >> x >> v; if ( A[x][ v / 64 ] & ( 1 << ( v % 64 ) ) ) cout << "TAK\n"; else cout << "NIE\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; } |