#include <functional>
#include <iostream>
using namespace std;
class Cache {
int n;
function<bool(int)> *predicates;
public:
explicit Cache(const int n, const int m) {
this->n = n;
this->predicates = new function<bool(int)>[m];
}
bool Contains(const int x, const int v) const {
return 1 <= x && x <= this->n ? v % x == 0 : this->predicates[x - this->n - 1](v);
}
void PutPredicate(const int i, const function<bool(int)> &predicate) const {
this->predicates[i] = predicate;
}
};
int main() {
// liczba początkowych zbiorów (zawieranie zdefiniowane przez podzielność)
int n;
// liczba operacji
int m;
// liczba zapytań
int q;
scanf("%d %d %d", &n, &m, &q); // NOLINT(*-err34-c)
auto *cache = new Cache(n, m);
for (int i = 0; i < m; i++) {
int op;
scanf("%d", &op); // NOLINT(*-multiway-paths-covered)
switch (op) {
// NOLINT(*-multiway-paths-covered)
case 1: {
int a, b;
scanf("%d %d", &a, &b); // NOLINT(*-err34-c)
cache->PutPredicate(i, [cache, a, b](const int v) {
return cache->Contains(a, v) || cache->Contains(b, v);
});
break;
}
case 2: {
int a, b;
scanf("%d %d", &a, &b); // NOLINT(*-err34-c)
cache->PutPredicate(i, [cache, a, b](const int v) {
return cache->Contains(a, v) && cache->Contains(b, v);
});
break;
}
case 3: {
int a;
scanf("%d", &a); // NOLINT(*-err34-c)
cache->PutPredicate(i, [cache, a](const int v) {
return !cache->Contains(a, v);
});
break;
}
}
}
for (int i = 0; i < q; i++) {
int x, v;
scanf("%d %d", &x, &v); // NOLINT(*-err34-c)
if (cache->Contains(x, v)) {
printf("TAK\n");
} else {
printf("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 | #include <functional> #include <iostream> using namespace std; class Cache { int n; function<bool(int)> *predicates; public: explicit Cache(const int n, const int m) { this->n = n; this->predicates = new function<bool(int)>[m]; } bool Contains(const int x, const int v) const { return 1 <= x && x <= this->n ? v % x == 0 : this->predicates[x - this->n - 1](v); } void PutPredicate(const int i, const function<bool(int)> &predicate) const { this->predicates[i] = predicate; } }; int main() { // liczba początkowych zbiorów (zawieranie zdefiniowane przez podzielność) int n; // liczba operacji int m; // liczba zapytań int q; scanf("%d %d %d", &n, &m, &q); // NOLINT(*-err34-c) auto *cache = new Cache(n, m); for (int i = 0; i < m; i++) { int op; scanf("%d", &op); // NOLINT(*-multiway-paths-covered) switch (op) { // NOLINT(*-multiway-paths-covered) case 1: { int a, b; scanf("%d %d", &a, &b); // NOLINT(*-err34-c) cache->PutPredicate(i, [cache, a, b](const int v) { return cache->Contains(a, v) || cache->Contains(b, v); }); break; } case 2: { int a, b; scanf("%d %d", &a, &b); // NOLINT(*-err34-c) cache->PutPredicate(i, [cache, a, b](const int v) { return cache->Contains(a, v) && cache->Contains(b, v); }); break; } case 3: { int a; scanf("%d", &a); // NOLINT(*-err34-c) cache->PutPredicate(i, [cache, a](const int v) { return !cache->Contains(a, v); }); break; } } } for (int i = 0; i < q; i++) { int x, v; scanf("%d %d", &x, &v); // NOLINT(*-err34-c) if (cache->Contains(x, v)) { printf("TAK\n"); } else { printf("NIE\n"); } } return 0; } |
English