#include <vector> #include <array> #include <iostream> #include <bitset> #define BASE 64 // sizeof(unsigned long long) #define SIZE 782 // 50000/sizeof(unsigned long long) #define OP_UNION 1 #define OP_INTER 2 #define OP_NEGAT 3 int get_size(int x) { return ((int)(x / BASE) + 1); } bool is_set(std::array<unsigned long long, SIZE> s, int val) { // std::cout << val << ' ' << s[(int)((val) / BASE)] << ' ' << (1 << ((val) % BASE)) << '\n'; return (bool)(s[(int)(val / BASE)] & (1ULL << (val % BASE))); } void set_fill(std::array<unsigned long long, SIZE> &s, int val, int n) { int pos = val; while (pos <= n) { s[(int)(pos / BASE)] |= (1ULL << (pos % BASE)); pos += val; } } void set_union(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, std::array<unsigned long long, SIZE> b, int size) { for (int i = 0; i < size; i++) { s[i] = a[i] | b[i]; } } void set_intersection(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, std::array<unsigned long long, SIZE> b, int size) { for (int i = 0; i < size; i++) { s[i] = a[i] & b[i]; } } void set_negation(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, int size) { for (int i = 0; i < size; i++) { s[i] = ~a[i]; } } std::vector<std::array<unsigned long long, SIZE>> data; int main() { int n, m, q, pos, op, a, b; std::cin >> n >> m >> q; data.resize(n + m + 1); for (int i = 1; i <= n; i++) { set_fill(data[i], i, n); } pos = n + 1; while (m--) { std::cin >> op; if (op == OP_UNION) { std::cin >> a >> b; // std::cout << op << ' ' << a << ' ' << b << '\n'; set_union(data[pos], data[a], data[b], get_size(n)); } else if (op == OP_INTER) { std::cin >> a >> b; // std::cout << op << ' ' << a << ' ' << b << '\n'; set_intersection(data[pos], data[a], data[b], get_size(n)); } else if (op == OP_NEGAT) { std::cin >> a; // std::cout << op << ' ' << a << '\n'; set_negation(data[pos], data[a], get_size(n)); } pos++; } while (q--) { std::cin >> a >> b; std::cout << (is_set(data[a], b) ? "TAK" : "NIE") << '\n'; } // std::cout << get_size(63) << '\n'; // std::cout << get_size(64) << '\n'; // std::cout << get_size(65) << '\n'; // for (int i = 0; i < 10; i++) // { // std::cout << (is_set(data[0], i) ? "TAK" : "NIE") << '\n'; // } // std::cout << sizeof(data[0]) << '\n'; // std::cout << data.size() << '\n'; // std::cout << data.capacity() << '\n'; // for (int i = 1; i < 10; i++) // { // std::cout << i << ' ' << is_set(data[0], i - 1) << '\n'; // } // for (int row = 0; row <= 40; row++) // { // for (int i = 1; i <= get_size(n); i++) // { // std::bitset<41> x(data[row][0]); // std::cout << x << "\n"; // } // std::cout << "---\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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #include <vector> #include <array> #include <iostream> #include <bitset> #define BASE 64 // sizeof(unsigned long long) #define SIZE 782 // 50000/sizeof(unsigned long long) #define OP_UNION 1 #define OP_INTER 2 #define OP_NEGAT 3 int get_size(int x) { return ((int)(x / BASE) + 1); } bool is_set(std::array<unsigned long long, SIZE> s, int val) { // std::cout << val << ' ' << s[(int)((val) / BASE)] << ' ' << (1 << ((val) % BASE)) << '\n'; return (bool)(s[(int)(val / BASE)] & (1ULL << (val % BASE))); } void set_fill(std::array<unsigned long long, SIZE> &s, int val, int n) { int pos = val; while (pos <= n) { s[(int)(pos / BASE)] |= (1ULL << (pos % BASE)); pos += val; } } void set_union(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, std::array<unsigned long long, SIZE> b, int size) { for (int i = 0; i < size; i++) { s[i] = a[i] | b[i]; } } void set_intersection(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, std::array<unsigned long long, SIZE> b, int size) { for (int i = 0; i < size; i++) { s[i] = a[i] & b[i]; } } void set_negation(std::array<unsigned long long, SIZE> &s, std::array<unsigned long long, SIZE> a, int size) { for (int i = 0; i < size; i++) { s[i] = ~a[i]; } } std::vector<std::array<unsigned long long, SIZE>> data; int main() { int n, m, q, pos, op, a, b; std::cin >> n >> m >> q; data.resize(n + m + 1); for (int i = 1; i <= n; i++) { set_fill(data[i], i, n); } pos = n + 1; while (m--) { std::cin >> op; if (op == OP_UNION) { std::cin >> a >> b; // std::cout << op << ' ' << a << ' ' << b << '\n'; set_union(data[pos], data[a], data[b], get_size(n)); } else if (op == OP_INTER) { std::cin >> a >> b; // std::cout << op << ' ' << a << ' ' << b << '\n'; set_intersection(data[pos], data[a], data[b], get_size(n)); } else if (op == OP_NEGAT) { std::cin >> a; // std::cout << op << ' ' << a << '\n'; set_negation(data[pos], data[a], get_size(n)); } pos++; } while (q--) { std::cin >> a >> b; std::cout << (is_set(data[a], b) ? "TAK" : "NIE") << '\n'; } // std::cout << get_size(63) << '\n'; // std::cout << get_size(64) << '\n'; // std::cout << get_size(65) << '\n'; // for (int i = 0; i < 10; i++) // { // std::cout << (is_set(data[0], i) ? "TAK" : "NIE") << '\n'; // } // std::cout << sizeof(data[0]) << '\n'; // std::cout << data.size() << '\n'; // std::cout << data.capacity() << '\n'; // for (int i = 1; i < 10; i++) // { // std::cout << i << ' ' << is_set(data[0], i - 1) << '\n'; // } // for (int row = 0; row <= 40; row++) // { // for (int i = 1; i <= get_size(n); i++) // { // std::bitset<41> x(data[row][0]); // std::cout << x << "\n"; // } // std::cout << "---\n"; // } return 0; } |