#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define MAX_N 50000
#define MAX_M 400000
#define MAX_Q 1000000
int main() {
uint64_t *sets[MAX_N + MAX_M];
int i, j, n, m, q, op, x, y, v;
scanf("%d%d%d", &n, &m, &q);
int setsize = (n + 63) / 64;
#define BIT_SET(nset, x) (sets[(nset)][(x) / 64] |= (1 << ((x) % 64)))
#define BIT_TEST(nset, x) (sets[(nset)][(x) / 64] & (1 << ((x) % 64)))
for (i = 0; i < n + m; i++) {
sets[i] = (uint64_t *)malloc(setsize);
}
for (i = 0; i < n; i++) {
for (j = i; j < n; j += (i + 1)) {
BIT_SET(i, j);
}
}
for (i = n; i < n + m; i++) {
scanf("%d", &op);
switch (op) {
case 1:
scanf("%d%d", &x, &y);
x--; y--;
for (j = 0; j < setsize; j++)
sets[i][j] = sets[x][j] | sets[y][j];
break;
case 2:
scanf("%d%d", &x, &y);
x--; y--;
for (j = 0; j < setsize; j++)
sets[i][j] = sets[x][j] & sets[y][j];
break;
case 3:
scanf("%d", &x);
x--;
for (j = 0; j < setsize; j++)
sets[i][j] = ~sets[x][j];
break;
}
}
for (i = 0; i < q; i++) {
scanf("%d%d", &x, &v); x--; v--;
puts(BIT_TEST(x, v) ? "TAK" : "NIE");
}
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 | #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #define MAX_N 50000 #define MAX_M 400000 #define MAX_Q 1000000 int main() { uint64_t *sets[MAX_N + MAX_M]; int i, j, n, m, q, op, x, y, v; scanf("%d%d%d", &n, &m, &q); int setsize = (n + 63) / 64; #define BIT_SET(nset, x) (sets[(nset)][(x) / 64] |= (1 << ((x) % 64))) #define BIT_TEST(nset, x) (sets[(nset)][(x) / 64] & (1 << ((x) % 64))) for (i = 0; i < n + m; i++) { sets[i] = (uint64_t *)malloc(setsize); } for (i = 0; i < n; i++) { for (j = i; j < n; j += (i + 1)) { BIT_SET(i, j); } } for (i = n; i < n + m; i++) { scanf("%d", &op); switch (op) { case 1: scanf("%d%d", &x, &y); x--; y--; for (j = 0; j < setsize; j++) sets[i][j] = sets[x][j] | sets[y][j]; break; case 2: scanf("%d%d", &x, &y); x--; y--; for (j = 0; j < setsize; j++) sets[i][j] = sets[x][j] & sets[y][j]; break; case 3: scanf("%d", &x); x--; for (j = 0; j < setsize; j++) sets[i][j] = ~sets[x][j]; break; } } for (i = 0; i < q; i++) { scanf("%d%d", &x, &v); x--; v--; puts(BIT_TEST(x, v) ? "TAK" : "NIE"); } return 0; } |
English