#include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 0; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; constexpr int maxn = 5e4, maxm = 4e5; bitset<maxn> full; vector<bitset<maxn>> a; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m, q; cin >> n >> m >> q; a.resize(n + m); rep(i, 0, n) for(ll j = i + 1; j < n + 1; j += i + 1) a[i][j - 1] = true; rep(i, 0, n) full[i] = true; DEBUG rep(i, 0, n) DC << a[i] << eol; DC << eol; rep(i, 0, m) { int x, y, z; cin >> x; if(x == 1) { cin >> y >> z; a[n + i] = a[y - 1] | a[z - 1]; } if(x == 2) { cin >> y >> z; a[n + i] = a[y - 1] & a[z - 1]; } if(x == 3) { cin >> y; a[n + i] = a[y - 1] ^ full; } DC << a[n + i] << eol; } rep(i, 0, q) { int x, y; cin >> x >> y; cout << (a[x-1][y-1] ? "TAK\n" : "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 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 0; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; constexpr int maxn = 5e4, maxm = 4e5; bitset<maxn> full; vector<bitset<maxn>> a; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m, q; cin >> n >> m >> q; a.resize(n + m); rep(i, 0, n) for(ll j = i + 1; j < n + 1; j += i + 1) a[i][j - 1] = true; rep(i, 0, n) full[i] = true; DEBUG rep(i, 0, n) DC << a[i] << eol; DC << eol; rep(i, 0, m) { int x, y, z; cin >> x; if(x == 1) { cin >> y >> z; a[n + i] = a[y - 1] | a[z - 1]; } if(x == 2) { cin >> y >> z; a[n + i] = a[y - 1] & a[z - 1]; } if(x == 3) { cin >> y; a[n + i] = a[y - 1] ^ full; } DC << a[n + i] << eol; } rep(i, 0, q) { int x, y; cin >> x >> y; cout << (a[x-1][y-1] ? "TAK\n" : "NIE\n"); } } |