#include <bits/stdc++.h> #define ll long long #define range(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, m, q; cin >> n >> m >> q; vector<bitset<50001>> zbiory; zbiory.resize(n+m); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { zbiory[i-1][j] = true; } } range(i, m) { int type; cin >> type; if (type == 1) { int x, y; cin >> x >> y; x--; y--; zbiory[n+i] = zbiory[x] | zbiory[y]; } else if (type == 2) { int x, y; cin >> x >> y; x--; y--; zbiory[n+i] = zbiory[x] & zbiory[y]; } else if (type == 3) { int x; cin >> x; x--; zbiory[n+i] = zbiory[x]; zbiory[n+i].flip(); } } range(i, q) { int x, v; cin >> x >> v; x--; cout << (zbiory[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 | #include <bits/stdc++.h> #define ll long long #define range(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, m, q; cin >> n >> m >> q; vector<bitset<50001>> zbiory; zbiory.resize(n+m); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { zbiory[i-1][j] = true; } } range(i, m) { int type; cin >> type; if (type == 1) { int x, y; cin >> x >> y; x--; y--; zbiory[n+i] = zbiory[x] | zbiory[y]; } else if (type == 2) { int x, y; cin >> x >> y; x--; y--; zbiory[n+i] = zbiory[x] & zbiory[y]; } else if (type == 3) { int x; cin >> x; x--; zbiory[n+i] = zbiory[x]; zbiory[n+i].flip(); } } range(i, q) { int x, v; cin >> x >> v; x--; cout << (zbiory[x][v] ? "TAK" : "NIE") << "\n"; } } |