#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
#define ary(k) array<int, k>
template <class A, class B> void cmx(A &x, B y) { x = max<A>(x, y); }
template <class A, class B> void cmn(A &x, B y) { x = min<A>(x, y); }
typedef pair<int, int> pii;
typedef vector<int> vi;
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
const int MM = 5e4 + 5;
int n, m, q;
cin >> n >> m >> q;
vector<bitset<MM>> a(n + m + 1);
rep(i, 1, n + 1) {
for (int j = i; j <= n; j += i)
a[i][j] = 1;
}
rep(i, n + 1, n + m + 1) {
int t, x;
cin >> t >> x;
if (t < 3) {
int y;
cin >> y;
if (t == 1)
a[i] = a[x] | a[y];
else
a[i] = a[x] & a[y];
} else {
a[i] = ~a[x];
}
}
while (q--) {
int x, v;
cin >> x >> v;
cout << (a[x][v] ? "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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define PB push_back #define FS first #define SD second #define ary(k) array<int, k> template <class A, class B> void cmx(A &x, B y) { x = max<A>(x, y); } template <class A, class B> void cmn(A &x, B y) { x = min<A>(x, y); } typedef pair<int, int> pii; typedef vector<int> vi; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); const int MM = 5e4 + 5; int n, m, q; cin >> n >> m >> q; vector<bitset<MM>> a(n + m + 1); rep(i, 1, n + 1) { for (int j = i; j <= n; j += i) a[i][j] = 1; } rep(i, n + 1, n + m + 1) { int t, x; cin >> t >> x; if (t < 3) { int y; cin >> y; if (t == 1) a[i] = a[x] | a[y]; else a[i] = a[x] & a[y]; } else { a[i] = ~a[x]; } } while (q--) { int x, v; cin >> x >> v; cout << (a[x][v] ? "TAK\n" : "NIE\n"); } } |
English