#include <iostream> #include <vector> #include <bitset> using namespace std; const int N = 50000; vector<bitset<N>> mainPointer; void init1(int n, int m) { mainPointer.resize(n + m + 1); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { mainPointer[i][j] = 1; } } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, q; cin >> n >> m >> q; init1(n, m); for (int i = 1; i <= m; i++) { short op; int x, y; cin >> op; if (op == 1) { cin >> x >> y; mainPointer[n + i] = mainPointer[x] | mainPointer[y]; // OR } else if (op == 2) { cin >> x >> y; mainPointer[n + i] = mainPointer[x] & mainPointer[y]; // AND } else if (op == 3) { cin >> x; mainPointer[n + i] = ~mainPointer[x]; // NOT } } for (int i = 1; i <= q; i++) { int x, v; cin >> x >> v; cout << (mainPointer[x][v] ? "TAK\n" : "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 | #include <iostream> #include <vector> #include <bitset> using namespace std; const int N = 50000; vector<bitset<N>> mainPointer; void init1(int n, int m) { mainPointer.resize(n + m + 1); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { mainPointer[i][j] = 1; } } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, q; cin >> n >> m >> q; init1(n, m); for (int i = 1; i <= m; i++) { short op; int x, y; cin >> op; if (op == 1) { cin >> x >> y; mainPointer[n + i] = mainPointer[x] | mainPointer[y]; // OR } else if (op == 2) { cin >> x >> y; mainPointer[n + i] = mainPointer[x] & mainPointer[y]; // AND } else if (op == 3) { cin >> x; mainPointer[n + i] = ~mainPointer[x]; // NOT } } for (int i = 1; i <= q; i++) { int x, v; cin >> x >> v; cout << (mainPointer[x][v] ? "TAK\n" : "NIE\n"); } return 0; } |