#include <iostream>
#include <set>
#include <vector>
using namespace std;
set<int> suma(set<int>& a, set<int>& b) {
set<int> res(a);
for (auto el : b) {
res.insert(el);
}
return res;
}
set<int> iloczyn(set<int>& a, set<int>& b) {
set<int> res;
for (auto el : a) {
if (b.find(el) != b.end()) {
res.insert(el);
}
}
return res;
}
set<int> negacja(set<int>& a, int n) {
set<int> res;
for (int i = 1; i <= n; i++) {
if (a.find(i) == a.end()) {
res.insert(i);
}
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<set<int>> zbiory(n + m + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j % i == 0) {
zbiory[i].insert(j);
}
}
}
int kodOperacji;
int x, y;
for (int i = n + 1; i <= n + m; i++) {
cin >> kodOperacji >> x;
if (kodOperacji < 3) cin >> y;
switch (kodOperacji)
{
case 1: zbiory[i] = suma(zbiory[x], zbiory[y]); break;
case 2: zbiory[i] = iloczyn(zbiory[x], zbiory[y]); break;
case 3: zbiory[i] = negacja(zbiory[x], n); break;
}
}
int nr, liczba;
for (int i = 0; i < q; i++) {
cin >> nr >> liczba;
if (zbiory[nr].find(liczba) != zbiory[nr].end()) {
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 | #include <iostream> #include <set> #include <vector> using namespace std; set<int> suma(set<int>& a, set<int>& b) { set<int> res(a); for (auto el : b) { res.insert(el); } return res; } set<int> iloczyn(set<int>& a, set<int>& b) { set<int> res; for (auto el : a) { if (b.find(el) != b.end()) { res.insert(el); } } return res; } set<int> negacja(set<int>& a, int n) { set<int> res; for (int i = 1; i <= n; i++) { if (a.find(i) == a.end()) { res.insert(i); } } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; vector<set<int>> zbiory(n + m + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j % i == 0) { zbiory[i].insert(j); } } } int kodOperacji; int x, y; for (int i = n + 1; i <= n + m; i++) { cin >> kodOperacji >> x; if (kodOperacji < 3) cin >> y; switch (kodOperacji) { case 1: zbiory[i] = suma(zbiory[x], zbiory[y]); break; case 2: zbiory[i] = iloczyn(zbiory[x], zbiory[y]); break; case 3: zbiory[i] = negacja(zbiory[x], n); break; } } int nr, liczba; for (int i = 0; i < q; i++) { cin >> nr >> liczba; if (zbiory[nr].find(liczba) != zbiory[nr].end()) { cout << "TAK\n"; } else { cout << "NIE\n"; } } return 0; } |
English