#include <bitset> #include <iostream> #include <vector> using namespace std; #define LIMIT 50000 typedef bitset<LIMIT> bset; vector<bset> sets; int n, m, q; bset getBset(int o, int x, int y); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; for(int i = 1; i <= n; i++) { bset bs; for(int j = 1; j <= LIMIT; j++) { if(j % i == 0) { bs[j-1] = 1; } } sets.push_back(bs); } for (int i = 0; i < m; i++) { int o, x, y = 0; cin >> o >> x; if (o < 3) { cin >> y; } sets.push_back(getBset(o, x, y)); } for (int i = 0; i < q; i++) { int x, v; cin >> x >> v; cout << (sets[x-1][v-1] ? "TAK" : "NIE") << endl; } return 0; } bset getBset(int o, int x, int y) { switch (o) { case 1: return sets[x-1] | sets[y-1]; case 2: return sets[x-1] & sets[y-1]; default: return ~sets[x-1]; } }
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 | #include <bitset> #include <iostream> #include <vector> using namespace std; #define LIMIT 50000 typedef bitset<LIMIT> bset; vector<bset> sets; int n, m, q; bset getBset(int o, int x, int y); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; for(int i = 1; i <= n; i++) { bset bs; for(int j = 1; j <= LIMIT; j++) { if(j % i == 0) { bs[j-1] = 1; } } sets.push_back(bs); } for (int i = 0; i < m; i++) { int o, x, y = 0; cin >> o >> x; if (o < 3) { cin >> y; } sets.push_back(getBset(o, x, y)); } for (int i = 0; i < q; i++) { int x, v; cin >> x >> v; cout << (sets[x-1][v-1] ? "TAK" : "NIE") << endl; } return 0; } bset getBset(int o, int x, int y) { switch (o) { case 1: return sets[x-1] | sets[y-1]; case 2: return sets[x-1] & sets[y-1]; default: return ~sets[x-1]; } } |