#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
const int N = 5e4+1;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
int m; cin >> m;
int q; cin >> q;
vector<bitset<N>> bs;
bs.reserve(n+m);
for(int i=1;i<=n;++i) {
bitset<N> a;
for(int j=i;j<=n;j+=i) {
a[j]=1;
}
bs.push_back(a);
}
for(int i=0;i<m;++i) {
int t,x; cin >> t >> x;
--x;
if(t==1) {
int y; cin >> y;
--y;
bs.push_back({bs[x]|bs[y]});
} else if(t==2) {
int y; cin >> y;
--y;
bs.push_back({bs[x]&bs[y]});
} else {
bs.push_back(~bs[x]);
}
}
while(q--) {
int x,v; cin >> x >> v;
--x;
cout << (bs[x][v]?"TAK":"NIE") << '\n';
}
}
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 | #include "bits/stdc++.h" using namespace std; #define all(x) x.begin(),x.end() template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #define ASSERT(...) 42 #endif typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int oo = 1e9; const int N = 5e4+1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int m; cin >> m; int q; cin >> q; vector<bitset<N>> bs; bs.reserve(n+m); for(int i=1;i<=n;++i) { bitset<N> a; for(int j=i;j<=n;j+=i) { a[j]=1; } bs.push_back(a); } for(int i=0;i<m;++i) { int t,x; cin >> t >> x; --x; if(t==1) { int y; cin >> y; --y; bs.push_back({bs[x]|bs[y]}); } else if(t==2) { int y; cin >> y; --y; bs.push_back({bs[x]&bs[y]}); } else { bs.push_back(~bs[x]); } } while(q--) { int x,v; cin >> x >> v; --x; cout << (bs[x][v]?"TAK":"NIE") << '\n'; } } |
English