#include <vector>
#include <iostream>
#define DEBUG 0
int n, m, q;
std::vector<std::vector<bool>> M;
void set_and(int idx, int x, int y) {
int i = idx + n;
for (int j = 1; j <= n; ++j) {
M[i][j] = M[x][j] && M[y][j];
}
}
void set_or(int idx, int x, int y) {
int i = idx + n;
for (int j = 1; j <= n; ++j) {
M[i][j] = M[x][j] || M[y][j];
}
}
void set_not(int idx, int x) {
int i = idx + n;
for (int j = 1; j <= n; ++j) {
M[i][j] = !M[x][j];
}
}
int main()
{
std::cin >> n >> m >> q;
M.resize(n + m + 1);
for (int i = 0; i <= n + m; ++i)
M[i].resize(n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
M[i][j] = (j % i == 0);
for (int i = 1; i <= m; ++i) {
int c, x, y;
std::cin >> c;
if (c == 1) {
std::cin >> x >> y;
set_or(i, x, y);
} else if (c == 2) {
std::cin >> x >> y;
set_and(i, x, y);
} else {
std::cin >> x;
set_not(i, x);
}
}
#if DEBUG
for (int i = 0; i < n+m; ++i) {
for (int j = 1; j <= n; ++j)
if (M[i][j])
std::cout << j << " ";
std::cout << std::endl;
}
#endif
for (int i = 0; i < q; ++i) {
int x, v;
std::cin >> x >> v;
if (M[x][v]) std::cout << "TAK\n";
else std::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 | #include <vector> #include <iostream> #define DEBUG 0 int n, m, q; std::vector<std::vector<bool>> M; void set_and(int idx, int x, int y) { int i = idx + n; for (int j = 1; j <= n; ++j) { M[i][j] = M[x][j] && M[y][j]; } } void set_or(int idx, int x, int y) { int i = idx + n; for (int j = 1; j <= n; ++j) { M[i][j] = M[x][j] || M[y][j]; } } void set_not(int idx, int x) { int i = idx + n; for (int j = 1; j <= n; ++j) { M[i][j] = !M[x][j]; } } int main() { std::cin >> n >> m >> q; M.resize(n + m + 1); for (int i = 0; i <= n + m; ++i) M[i].resize(n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) M[i][j] = (j % i == 0); for (int i = 1; i <= m; ++i) { int c, x, y; std::cin >> c; if (c == 1) { std::cin >> x >> y; set_or(i, x, y); } else if (c == 2) { std::cin >> x >> y; set_and(i, x, y); } else { std::cin >> x; set_not(i, x); } } #if DEBUG for (int i = 0; i < n+m; ++i) { for (int j = 1; j <= n; ++j) if (M[i][j]) std::cout << j << " "; std::cout << std::endl; } #endif for (int i = 0; i < q; ++i) { int x, v; std::cin >> x >> v; if (M[x][v]) std::cout << "TAK\n"; else std::cout << "NIE\n"; } return 0; } |
English