#include <iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
vector<set<int>> collections;
vector<set<int>> formCollections(int& n) {
vector<set<int>> c = {};
for (int i = 1; i <= n; i++)
{
set<int> An = {};
for (int j = i; j <= n; j += i)
An.insert(j);
c.push_back(An);
}
return c;
}
set<int> makeOperation(int op, int x, int y, int n) {
set<int> c = {};
switch(op)
{
case 1:
c = collections[x - 1];
c.insert(collections[y-1].begin(), collections[y - 1].end());
break;
case 2:
set_intersection(collections[x - 1].begin(), collections[x - 1].end(), collections[y - 1].begin(), collections[y - 1].end(),
inserter(c, c.begin()));
break;
default: // 3
set<int> allSet;
for (int i = 1; i <= n; i++)
allSet.insert(i);
//cout << "PRINTING ALLSET: \n";
//for (auto val : allSet) {
// cout << val << " ";
//}
//cout << endl;
//cout << "PRINTING COLLECTIONS: \n";
//for (auto val : collections[x - 1]) {
// cout << val << " ";
//}
//cout << endl;
set_difference(allSet.begin(), allSet.end(), collections[x - 1].begin(), collections[x - 1].end(),
inserter(c, c.begin()));
break;
}
return c;
}
int main()
{
//////////////////////////////////
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//////////////////////////////////
int n, m, q;
cin >> n >> m >> q;
collections = formCollections(n);
for (int i = 0; i < m; i++)
{
int o, x, y{};
cin >> o;
if (o < 3) cin >> x >> y;
else cin >> x;
collections.push_back(makeOperation(o, x, y, n));
}
for (int i = 0; i < q; i++)
{
int x, v;
cin >> x >> v;
if (collections[x - 1].count(v)) cout << "TAK\n";
else cout << "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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <iostream> #include<vector> #include<set> #include<algorithm> using namespace std; vector<set<int>> collections; vector<set<int>> formCollections(int& n) { vector<set<int>> c = {}; for (int i = 1; i <= n; i++) { set<int> An = {}; for (int j = i; j <= n; j += i) An.insert(j); c.push_back(An); } return c; } set<int> makeOperation(int op, int x, int y, int n) { set<int> c = {}; switch(op) { case 1: c = collections[x - 1]; c.insert(collections[y-1].begin(), collections[y - 1].end()); break; case 2: set_intersection(collections[x - 1].begin(), collections[x - 1].end(), collections[y - 1].begin(), collections[y - 1].end(), inserter(c, c.begin())); break; default: // 3 set<int> allSet; for (int i = 1; i <= n; i++) allSet.insert(i); //cout << "PRINTING ALLSET: \n"; //for (auto val : allSet) { // cout << val << " "; //} //cout << endl; //cout << "PRINTING COLLECTIONS: \n"; //for (auto val : collections[x - 1]) { // cout << val << " "; //} //cout << endl; set_difference(allSet.begin(), allSet.end(), collections[x - 1].begin(), collections[x - 1].end(), inserter(c, c.begin())); break; } return c; } int main() { ////////////////////////////////// ios_base::sync_with_stdio(false); cin.tie(NULL); ////////////////////////////////// int n, m, q; cin >> n >> m >> q; collections = formCollections(n); for (int i = 0; i < m; i++) { int o, x, y{}; cin >> o; if (o < 3) cin >> x >> y; else cin >> x; collections.push_back(makeOperation(o, x, y, n)); } for (int i = 0; i < q; i++) { int x, v; cin >> x >> v; if (collections[x - 1].count(v)) cout << "TAK\n"; else cout << "NIE\n"; } return 0; } |
English