#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
constexpr int NMM = 10000;
constexpr int CM = 790;
ll T[NMM][CM];
int C;
void sumop(int w, int x, int y) {
for (int i = 0; i < C; i++)
T[w][i] = T[x][i] | T[y][i];
}
void andop(int w, int x, int y) {
for (int i = 0; i < C; i++)
T[w][i] = T[x][i] & T[y][i];
}
void negop(int w, int x) {
for (int i = 0; i < C; i++) {
T[w][i] = ~T[x][i];
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
C = (n >> 6) + 1;
for (int i = 0; i < C; i++) { T[1][i] = -1; }
for (int i = 2; i <= n; ++i) {
int c, p;
for (int j = i; j < n; j += i) {
c = j >> 6;
p = j % 64;
T[i][c] |= 1LL << p;
}
}
int k, x, y, v;
for (int i = 1; i <= m; ++i) {
cin >> k;
if (k == 1) {
cin >> x >> y;
sumop(n + i, x, y);
} else if (k == 2) {
cin >> x >> y;
andop(n + i, x, y);
} else {
cin >> x;
negop(n + i, x);
}
}
int c, p;
for (int i = 0; i < q; i++) {
cin >> x >> v;
c = v >> 6;
p = v % 64;
cout << ((T[x][c] & 1LL << p) != 0 ? "TAK" : "NIE") << "\n";
cout.flush();
}
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 | #include <algorithm> #include <iostream> using namespace std; typedef long long ll; constexpr int NMM = 10000; constexpr int CM = 790; ll T[NMM][CM]; int C; void sumop(int w, int x, int y) { for (int i = 0; i < C; i++) T[w][i] = T[x][i] | T[y][i]; } void andop(int w, int x, int y) { for (int i = 0; i < C; i++) T[w][i] = T[x][i] & T[y][i]; } void negop(int w, int x) { for (int i = 0; i < C; i++) { T[w][i] = ~T[x][i]; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n, m, q; cin >> n >> m >> q; C = (n >> 6) + 1; for (int i = 0; i < C; i++) { T[1][i] = -1; } for (int i = 2; i <= n; ++i) { int c, p; for (int j = i; j < n; j += i) { c = j >> 6; p = j % 64; T[i][c] |= 1LL << p; } } int k, x, y, v; for (int i = 1; i <= m; ++i) { cin >> k; if (k == 1) { cin >> x >> y; sumop(n + i, x, y); } else if (k == 2) { cin >> x >> y; andop(n + i, x, y); } else { cin >> x; negop(n + i, x); } } int c, p; for (int i = 0; i < q; i++) { cin >> x >> v; c = v >> 6; p = v % 64; cout << ((T[x][c] & 1LL << p) != 0 ? "TAK" : "NIE") << "\n"; cout.flush(); } return 0; } |
English