#include <bitset>
#include <cassert>
#include <iostream>
using namespace std;
#define all(a) begin(a), end(a)
using ll = long long;
constexpr int N = 5e4 + 1;
using B = bitset<N>;
void solve() {
int n, m, q;
cin >> n >> m >> q;
B res[n + m + 1];
for (int i = 1; i <= n; i++) {
res[i].reset();
for (int j = i; j <= n; j += i) {
cerr << i << " " << j << "\n";
res[i][j] = 1;
}
}
for (int i = n + 1; i <= n + m; i++) {
int type;
cin >> type;
if (type == 1) {
int x, y;
cin >> x >> y;
res[i] = res[x] | res[y];
} else if (type == 2) {
int x, y;
cin >> x >> y;
res[i] = res[x] & res[y];
} else {
int x;
cin >> x;
res[i] = ~res[x];
}
}
while (q--) {
int i, x;
cin >> i >> x;
cout << (res[i][x] ? "TAK\n" : "NIE\n");
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int tests = 1;
// cin >> tests;
while (tests--)
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 | #include <bitset> #include <cassert> #include <iostream> using namespace std; #define all(a) begin(a), end(a) using ll = long long; constexpr int N = 5e4 + 1; using B = bitset<N>; void solve() { int n, m, q; cin >> n >> m >> q; B res[n + m + 1]; for (int i = 1; i <= n; i++) { res[i].reset(); for (int j = i; j <= n; j += i) { cerr << i << " " << j << "\n"; res[i][j] = 1; } } for (int i = n + 1; i <= n + m; i++) { int type; cin >> type; if (type == 1) { int x, y; cin >> x >> y; res[i] = res[x] | res[y]; } else if (type == 2) { int x, y; cin >> x >> y; res[i] = res[x] & res[y]; } else { int x; cin >> x; res[i] = ~res[x]; } } while (q--) { int i, x; cin >> i >> x; cout << (res[i][x] ? "TAK\n" : "NIE\n"); } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int tests = 1; // cin >> tests; while (tests--) solve(); } |
English