#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int INF = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define pb push_back
#define cmax(x, y) (x = max(x, y))
#define cmin(x, y) (x = min(x, y))
#ifdef LOCAL
#include "debug.cpp"
#else
#define debug(x...)
#endif
const int MAXN = 5e4 + 5;
void solve() {
int n, m, q;
cin >> n >> m >> q;
vector <bitset <MAXN>> v(n + m + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j * j <= n; j++) {
if (i % j == 0) {
v[j][i] = 1;
v[i / j][i] = 1;
}
}
}
int o, x, y;
for (int i = n + 1; i <= n + m; i++) {
cin >> o;
if (o == 1) {
cin >> x >> y;
v[i] = v[x] | v[y];
} else if (o == 2) {
cin >> x >> y;
v[i] = v[x] & v[y];
} else {
cin >> x;
v[i] = ~v[x];
}
}
while (q--) {
cin >> x >> y;
cout << (v[x][y] ? "TAK\n" : "NIE\n");
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
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 | #include "bits/stdc++.h" using namespace std; using ll = long long; const int INF = 1e9 + 7; #define all(x) x.begin(), x.end() #define pb push_back #define cmax(x, y) (x = max(x, y)) #define cmin(x, y) (x = min(x, y)) #ifdef LOCAL #include "debug.cpp" #else #define debug(x...) #endif const int MAXN = 5e4 + 5; void solve() { int n, m, q; cin >> n >> m >> q; vector <bitset <MAXN>> v(n + m + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j * j <= n; j++) { if (i % j == 0) { v[j][i] = 1; v[i / j][i] = 1; } } } int o, x, y; for (int i = n + 1; i <= n + m; i++) { cin >> o; if (o == 1) { cin >> x >> y; v[i] = v[x] | v[y]; } else if (o == 2) { cin >> x >> y; v[i] = v[x] & v[y]; } else { cin >> x; v[i] = ~v[x]; } } while (q--) { cin >> x >> y; cout << (v[x][y] ? "TAK\n" : "NIE\n"); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); } |
English