#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define vec vector
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
const int _n=50001;
void slv(){
int n,m,q;
cin>>n>>m>>q;
vec<bitset<_n>> a(450101);
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j+=i){
a[i][j]=1;
}
}
bitset<_n> tmp;
for(int i=1;i<=n;i++) tmp[i]=1;
for(int i=1;i<=m;i++){
int typ;
cin>>typ;
if(typ==1){
int x,y;
cin>>x>>y;
a[i+n]=a[x]|a[y];
}else if(typ==2){
int x,y;
cin>>x>>y;
a[i+n]=a[x]&a[y];
}else{
int x;
cin>>x;
a[i+n]=a[x]^tmp;
}
}
for(int i=1;i<=q;i++){
int x,v;
cin>>x>>v;
cout<<(a[x][v]?"TAK":"NIE")<<"\n";
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
int t;
t=1;
// cin>>t;
rep(cs,t){
slv();
}
}
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 | #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rng(i,c,n) for(int i=c;i<n;i++) #define fi first #define se second #define vec vector #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} const int _n=50001; void slv(){ int n,m,q; cin>>n>>m>>q; vec<bitset<_n>> a(450101); for(int i=1;i<=n;i++){ for(int j=i;j<=n;j+=i){ a[i][j]=1; } } bitset<_n> tmp; for(int i=1;i<=n;i++) tmp[i]=1; for(int i=1;i<=m;i++){ int typ; cin>>typ; if(typ==1){ int x,y; cin>>x>>y; a[i+n]=a[x]|a[y]; }else if(typ==2){ int x,y; cin>>x>>y; a[i+n]=a[x]&a[y]; }else{ int x; cin>>x; a[i+n]=a[x]^tmp; } } for(int i=1;i<=q;i++){ int x,v; cin>>x>>v; cout<<(a[x][v]?"TAK":"NIE")<<"\n"; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0); int t; t=1; // cin>>t; rep(cs,t){ slv(); } } |
English