#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> A(n + m + 1);
vector<int> Universum;
for (int i = 1; i <= n; ++i)
{
Universum.push_back(i);
for (int j = 1; j <= n; ++j)
{
if (i % j == 0)
{
A[j].push_back(i);
}
}
}
for (int i = 1; i <= m; ++i)
{
int op;
cin >> op;
if (op == 1)
{
int x, y;
cin >> x >> y;
set_union(A[x].begin(), A[x].end(), A[y].begin(), A[y].end(), inserter(A[n + i], A[n + i].begin()));
}
else if (op == 2)
{
int x, y;
cin >> x >> y;
set_intersection(A[x].begin(), A[x].end(), A[y].begin(), A[y].end(), inserter(A[n + i], A[n + i].begin()));
}
else if (op == 3)
{
int x;
cin >> x;
set_difference(Universum.begin(), Universum.end(), A[x].begin(), A[x].end(), inserter(A[n + i], A[n + i].begin()));
}
}
for (int i = 0; i < q; ++i)
{
int x, v;
cin >> x >> v;
cout << (binary_search(A[x].begin(), A[x].end(), v) ? "TAK" : "NIE") << '\n';
}
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 61 62 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; vector<vector<int>> A(n + m + 1); vector<int> Universum; for (int i = 1; i <= n; ++i) { Universum.push_back(i); for (int j = 1; j <= n; ++j) { if (i % j == 0) { A[j].push_back(i); } } } for (int i = 1; i <= m; ++i) { int op; cin >> op; if (op == 1) { int x, y; cin >> x >> y; set_union(A[x].begin(), A[x].end(), A[y].begin(), A[y].end(), inserter(A[n + i], A[n + i].begin())); } else if (op == 2) { int x, y; cin >> x >> y; set_intersection(A[x].begin(), A[x].end(), A[y].begin(), A[y].end(), inserter(A[n + i], A[n + i].begin())); } else if (op == 3) { int x; cin >> x; set_difference(Universum.begin(), Universum.end(), A[x].begin(), A[x].end(), inserter(A[n + i], A[n + i].begin())); } } for (int i = 0; i < q; ++i) { int x, v; cin >> x >> v; cout << (binary_search(A[x].begin(), A[x].end(), v) ? "TAK" : "NIE") << '\n'; } return 0; } |
English