#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int M = 64;
bitset<M> B[450005];
bool ans[1000005];
int nxt[50005];
struct Oper {
int type, x, y;
};
int main() {
ios_base::sync_with_stdio(0);
int n, m, q;
cin>>n>>m>>q;
int N = n/M+2;
vector<Oper> opers;
for(int i=n+1;i<=n+m;i++) {
int type;
cin>>type;
if(type == 1) {
int x, y;
cin>>x>>y;
opers.push_back({type, x, y});
}
else if(type == 2) {
int x, y;
cin>>x>>y;
opers.push_back({type, x, y});
}
else {
int x;
cin>>x;
opers.push_back({type, x, 0});
}
}
vector<vector<PII>> Q(n+200);
for(int i=0;i<q;i++) {
int x,y;
cin>>x>>y;
Q[y].push_back({x, i});
}
for(int k=0;k<N;k++) {
for(int i=1;i<=n;i++) {
B[i].reset();
while(nxt[i] < (k+1)*M) {
B[i][nxt[i]&(M-1)] = 1;
nxt[i] += i;
}
// for(int j=k*M;j<(k+1)*M;j++) {
// if(j%i == 0) B[i][j&(M-1)] = 1;
// else B[i][j&(M-1)] = 0;
// }
}
int i = n;
for(auto [type, x, y]: opers) {
i++;
if(type == 1) {
B[i] = B[x] | B[y];
}
else if(type == 2) {
B[i] = B[x] & B[y];
}
else {
B[i] = ~B[x];
}
}
for(int j=k*M;j<(k+1)*M;j++) {
for(auto [x, ind]: Q[j]) {
if(B[x][j&(M-1)]) ans[ind] = true;
}
}
}
for(int i=0;i<q;i++) {
if(ans[i]) cout<<"TAK\n";
else cout<<"NIE\n";
}
}
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 | #include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int M = 64; bitset<M> B[450005]; bool ans[1000005]; int nxt[50005]; struct Oper { int type, x, y; }; int main() { ios_base::sync_with_stdio(0); int n, m, q; cin>>n>>m>>q; int N = n/M+2; vector<Oper> opers; for(int i=n+1;i<=n+m;i++) { int type; cin>>type; if(type == 1) { int x, y; cin>>x>>y; opers.push_back({type, x, y}); } else if(type == 2) { int x, y; cin>>x>>y; opers.push_back({type, x, y}); } else { int x; cin>>x; opers.push_back({type, x, 0}); } } vector<vector<PII>> Q(n+200); for(int i=0;i<q;i++) { int x,y; cin>>x>>y; Q[y].push_back({x, i}); } for(int k=0;k<N;k++) { for(int i=1;i<=n;i++) { B[i].reset(); while(nxt[i] < (k+1)*M) { B[i][nxt[i]&(M-1)] = 1; nxt[i] += i; } // for(int j=k*M;j<(k+1)*M;j++) { // if(j%i == 0) B[i][j&(M-1)] = 1; // else B[i][j&(M-1)] = 0; // } } int i = n; for(auto [type, x, y]: opers) { i++; if(type == 1) { B[i] = B[x] | B[y]; } else if(type == 2) { B[i] = B[x] & B[y]; } else { B[i] = ~B[x]; } } for(int j=k*M;j<(k+1)*M;j++) { for(auto [x, ind]: Q[j]) { if(B[x][j&(M-1)]) ans[ind] = true; } } } for(int i=0;i<q;i++) { if(ans[i]) cout<<"TAK\n"; else cout<<"NIE\n"; } } |
English