#include <iostream> #include <bitset> #include <vector> using namespace std; const int MAX_N = 50000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; vector<bitset<MAX_N>> zbiory; zbiory.reserve(n + m); for (int i = 1; i <= n; i++) { bitset<MAX_N> zbior; for (int j = i; j <= n; j += i) { zbior.set(j - 1); } zbiory.push_back(zbior); } int op, x, y; for (int i = 0; i < m; i++) { cin >> op; if (op == 1) { cin >> x >> y; bitset<MAX_N> zbior = zbiory[x - 1] | zbiory[y - 1]; zbiory.push_back(zbior); } else if (op == 2) { cin >> x >> y; bitset<MAX_N> zbior = zbiory[x - 1] & zbiory[y - 1]; zbiory.push_back(zbior); } else { cin >> x; bitset<MAX_N> zbior = ~zbiory[x - 1]; zbiory.push_back(zbior); } } int v; for (int i = 0; i < q; i++) { cin >> x >> v; if (zbiory[x - 1][v - 1]) cout << "TAK\n"; else cout << "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 56 57 58 59 60 61 62 63 | #include <iostream> #include <bitset> #include <vector> using namespace std; const int MAX_N = 50000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; vector<bitset<MAX_N>> zbiory; zbiory.reserve(n + m); for (int i = 1; i <= n; i++) { bitset<MAX_N> zbior; for (int j = i; j <= n; j += i) { zbior.set(j - 1); } zbiory.push_back(zbior); } int op, x, y; for (int i = 0; i < m; i++) { cin >> op; if (op == 1) { cin >> x >> y; bitset<MAX_N> zbior = zbiory[x - 1] | zbiory[y - 1]; zbiory.push_back(zbior); } else if (op == 2) { cin >> x >> y; bitset<MAX_N> zbior = zbiory[x - 1] & zbiory[y - 1]; zbiory.push_back(zbior); } else { cin >> x; bitset<MAX_N> zbior = ~zbiory[x - 1]; zbiory.push_back(zbior); } } int v; for (int i = 0; i < q; i++) { cin >> x >> v; if (zbiory[x - 1][v - 1]) cout << "TAK\n"; else cout << "NIE\n"; } } |