#include <iostream>
#include <set>
#include <vector>
int main()
{
std::vector<std::set<int>> listOfSets;
int n, m, q;
std::cin >> n >> m >> q;
for(int i = 1; i <= n; i++)
{
std::set<int> set;
for (int j = 1; j <= n; j++)
{
if (j % i == 0)
set.insert(j);
}
listOfSets.push_back(set);
}
for (int i = 1; i <= m; i++)
{
int op, x, y;
std::cin >> op;
std::set<int> set;
switch (op)
{
case 1:
std::cin >> x >> y;
for (int j : listOfSets.at(x - 1))
{
set.insert(j);
}
for (int j : listOfSets.at(y - 1))
{
set.insert(j);
}
break;
case 2:
std::cin >> x >> y;
for (int j : listOfSets.at(x - 1))
{
if(listOfSets.at(y - 1).find(j) != listOfSets.at(y - 1).end())
set.insert(j);
}
break;
case 3:
std::cin >> x;
for (int j = 1; j <= n; j++)
{
if (listOfSets.at(x - 1).find(j) == listOfSets.at(x - 1).end())
set.insert(j);
}
break;
}
listOfSets.push_back(set);
}
for (int i = 1; i <= q; i++)
{
int x, y;
std::cin >> x >> y;
std::string answer = (listOfSets.at(x - 1).find(y) != listOfSets.at(x - 1).end()) ? "TAK" : "NIE";
std::cout << answer << std::endl;
}
}
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 | #include <iostream> #include <set> #include <vector> int main() { std::vector<std::set<int>> listOfSets; int n, m, q; std::cin >> n >> m >> q; for(int i = 1; i <= n; i++) { std::set<int> set; for (int j = 1; j <= n; j++) { if (j % i == 0) set.insert(j); } listOfSets.push_back(set); } for (int i = 1; i <= m; i++) { int op, x, y; std::cin >> op; std::set<int> set; switch (op) { case 1: std::cin >> x >> y; for (int j : listOfSets.at(x - 1)) { set.insert(j); } for (int j : listOfSets.at(y - 1)) { set.insert(j); } break; case 2: std::cin >> x >> y; for (int j : listOfSets.at(x - 1)) { if(listOfSets.at(y - 1).find(j) != listOfSets.at(y - 1).end()) set.insert(j); } break; case 3: std::cin >> x; for (int j = 1; j <= n; j++) { if (listOfSets.at(x - 1).find(j) == listOfSets.at(x - 1).end()) set.insert(j); } break; } listOfSets.push_back(set); } for (int i = 1; i <= q; i++) { int x, y; std::cin >> x >> y; std::string answer = (listOfSets.at(x - 1).find(y) != listOfSets.at(x - 1).end()) ? "TAK" : "NIE"; std::cout << answer << std::endl; } } |
English