#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<bool> vb; typedef vector<vb> vvb; #define ALL(x) begin(x), end(x) #define pb push_back #define mp make_pair #define fi first #define se second #define printBool(x) cout << ((x) ? "TAK\n" : "NIE\n") #define printBoolR(x) {cout << ((x) ? "TAK\n" : "NIE\n"); return;} inline ll nxt(){ll x;cin>>x;return x;} #define fill_i(x) generate(ALL(x), nxt) const int MAX_N = 50000; void testCase(int caseNr) { int n, m, q; cin >> n >> m >> q; vector<bitset<MAX_N>> can_visit(n); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { can_visit[i-1][j-1] = 1; } } for (int i = 0; i < m; i++) { int t; cin >> t; if (t == 1) { int x, y; cin >> x >> y; x--, y--; can_visit.push_back(can_visit[x] | can_visit[y]); } else if (t == 2) { int x, y; cin >> x >> y; x--, y--; can_visit.push_back(can_visit[x] & can_visit[y]); } else { int x; cin >> x; x--; can_visit.push_back(~can_visit[x]); } } for (int i = 0; i < q; i++) { int x, v; cin >> x >> v; printBool(can_visit[x-1][v-1]); } } int main() { // freopen("input", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); // int T; cin >> T; for (int t = 1; t <= T; t++) testCase(t); testCase(0); 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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<bool> vb; typedef vector<vb> vvb; #define ALL(x) begin(x), end(x) #define pb push_back #define mp make_pair #define fi first #define se second #define printBool(x) cout << ((x) ? "TAK\n" : "NIE\n") #define printBoolR(x) {cout << ((x) ? "TAK\n" : "NIE\n"); return;} inline ll nxt(){ll x;cin>>x;return x;} #define fill_i(x) generate(ALL(x), nxt) const int MAX_N = 50000; void testCase(int caseNr) { int n, m, q; cin >> n >> m >> q; vector<bitset<MAX_N>> can_visit(n); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { can_visit[i-1][j-1] = 1; } } for (int i = 0; i < m; i++) { int t; cin >> t; if (t == 1) { int x, y; cin >> x >> y; x--, y--; can_visit.push_back(can_visit[x] | can_visit[y]); } else if (t == 2) { int x, y; cin >> x >> y; x--, y--; can_visit.push_back(can_visit[x] & can_visit[y]); } else { int x; cin >> x; x--; can_visit.push_back(~can_visit[x]); } } for (int i = 0; i < q; i++) { int x, v; cin >> x >> v; printBool(can_visit[x-1][v-1]); } } int main() { // freopen("input", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); // int T; cin >> T; for (int t = 1; t <= T; t++) testCase(t); testCase(0); return 0; } |