#include <bits/stdc++.h> using namespace std; enum OpType { UNION = 1, INTERSECTION = 2, NEGATION = 3 }; struct Op { int type; int setA, setB; }; struct Query { int setIdx, val; }; const int MAX_N = 50005; struct State { bitset<MAX_N> bits; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, q, i, j; cin >> n >> m >> q; vector<State> states(n + m + 1); for (i = 1; i <= n; ++i) { for (j = i; j <= n; j += i) { states[i].bits.set(j); } } Op op; for (i = 0; i < m; ++i) { cin >> op.type >> op.setA; if (op.type != 3) { cin >> op.setB; } int currStateIdx = n + i + 1; if (op.type == UNION) { states[currStateIdx].bits = states[op.setA].bits | states[op.setB].bits; } else if (op.type == INTERSECTION) { states[currStateIdx].bits = states[op.setA].bits & states[op.setB].bits; } else if (op.type == NEGATION) { states[currStateIdx].bits = states[op.setA].bits; states[currStateIdx].bits.flip(); } } Query query; for (i = 0; i < q; ++i) { cin >> query.setIdx >> query.val; if (states[query.setIdx].bits.test(query.val)) { 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 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 | #include <bits/stdc++.h> using namespace std; enum OpType { UNION = 1, INTERSECTION = 2, NEGATION = 3 }; struct Op { int type; int setA, setB; }; struct Query { int setIdx, val; }; const int MAX_N = 50005; struct State { bitset<MAX_N> bits; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, q, i, j; cin >> n >> m >> q; vector<State> states(n + m + 1); for (i = 1; i <= n; ++i) { for (j = i; j <= n; j += i) { states[i].bits.set(j); } } Op op; for (i = 0; i < m; ++i) { cin >> op.type >> op.setA; if (op.type != 3) { cin >> op.setB; } int currStateIdx = n + i + 1; if (op.type == UNION) { states[currStateIdx].bits = states[op.setA].bits | states[op.setB].bits; } else if (op.type == INTERSECTION) { states[currStateIdx].bits = states[op.setA].bits & states[op.setB].bits; } else if (op.type == NEGATION) { states[currStateIdx].bits = states[op.setA].bits; states[currStateIdx].bits.flip(); } } Query query; for (i = 0; i < q; ++i) { cin >> query.setIdx >> query.val; if (states[query.setIdx].bits.test(query.val)) { cout << "TAK\n"; } else { cout << "NIE\n"; } } return 0; } |