#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef uint64_t ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long> vll; constexpr ll LINF = 1e18; constexpr int INF = 1e9; constexpr int N = 50000; constexpr int M = 400000; constexpr int N_WORDS = N / 64 + 1; uint64_t (*sets)[N_WORDS]; void sum(int set_out, int set_i, int set_j, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = sets[set_i][i] | sets[set_j][i]; } } void intersection(int set_out, int set_i, int set_j, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = sets[set_i][i] & sets[set_j][i]; } } void complement(int set_out, int set_i, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = ~sets[set_i][i]; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; sets = new ull[n + m + 1][N_WORDS]{}; int n_words = n / 64 + 1; for (int i = 1; i <= n; ++i) { int k = i; while (k <= n) { sets[i][k >> 6] |= 1ULL << (k & 63); k += i; } } int op, x, y; for (int i = 0; i < m; ++i) { cin >> op; if (op == 1) { cin >> x >> y; sum(n + i + 1, x, y, n_words); } else if (op == 2) { cin >> x >> y; intersection(n + i + 1, x, y, n_words); } else { cin >> x; complement(n + i + 1, x, n_words); } } int v; for (int i = 0; i < q; ++i) { cin >> x >> v; if ((sets[x][v >> 6] >> (v & 63)) & 1ULL) { cout << "TAK\n"; } else { 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 75 76 77 78 79 80 81 82 83 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef uint64_t ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long> vll; constexpr ll LINF = 1e18; constexpr int INF = 1e9; constexpr int N = 50000; constexpr int M = 400000; constexpr int N_WORDS = N / 64 + 1; uint64_t (*sets)[N_WORDS]; void sum(int set_out, int set_i, int set_j, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = sets[set_i][i] | sets[set_j][i]; } } void intersection(int set_out, int set_i, int set_j, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = sets[set_i][i] & sets[set_j][i]; } } void complement(int set_out, int set_i, int n_words) { for (int i = 0; i < n_words; ++i) { sets[set_out][i] = ~sets[set_i][i]; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; sets = new ull[n + m + 1][N_WORDS]{}; int n_words = n / 64 + 1; for (int i = 1; i <= n; ++i) { int k = i; while (k <= n) { sets[i][k >> 6] |= 1ULL << (k & 63); k += i; } } int op, x, y; for (int i = 0; i < m; ++i) { cin >> op; if (op == 1) { cin >> x >> y; sum(n + i + 1, x, y, n_words); } else if (op == 2) { cin >> x >> y; intersection(n + i + 1, x, y, n_words); } else { cin >> x; complement(n + i + 1, x, n_words); } } int v; for (int i = 0; i < q; ++i) { cin >> x >> v; if ((sets[x][v >> 6] >> (v & 63)) & 1ULL) { cout << "TAK\n"; } else { cout << "NIE\n"; } } return 0; } |