#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=1e4,M=4.5e5+5,K=1e6+5; int n,m,q; int ans[K]; bitset<N>F[M]; pair<int,int>Q[K]; tuple<int,int,int>A[M]; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>m>>q; for(int i=1;i<=m;++i){ int o,x,y;cin>>o>>x; if(o!=3)cin>>y; A[i]=make_tuple(o,x,y); } for(int i=1;i<=q;++i){ int x,y;cin>>x>>y; Q[i]=make_pair(x,y); } for(int l=1,r=1e4;l<=n;l=r+1,r+=1e4){ for(int i=1;i<=n;++i)F[i].reset(); for(int i=1;i<=n;++i) for(int j=i;j<=n;j+=i)if(l<=j&&j<=r) F[i][j-l]=1; for(int i=1;i<=m;++i){ const auto [o,x,y]=A[i]; if(o==1)F[n+i]=F[x]|F[y]; else if(o==2)F[n+i]=F[x]&F[y]; else F[n+i]=~F[x]; } for(int i=1;i<=q;++i){ const auto [x,y]=Q[i]; if(l<=y&&y<=r)ans[i]=F[x].test(y-l); } } for(int i=1;i<=q;++i) cout<<(ans[i]?"TAK\n":"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 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=1e4,M=4.5e5+5,K=1e6+5; int n,m,q; int ans[K]; bitset<N>F[M]; pair<int,int>Q[K]; tuple<int,int,int>A[M]; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>m>>q; for(int i=1;i<=m;++i){ int o,x,y;cin>>o>>x; if(o!=3)cin>>y; A[i]=make_tuple(o,x,y); } for(int i=1;i<=q;++i){ int x,y;cin>>x>>y; Q[i]=make_pair(x,y); } for(int l=1,r=1e4;l<=n;l=r+1,r+=1e4){ for(int i=1;i<=n;++i)F[i].reset(); for(int i=1;i<=n;++i) for(int j=i;j<=n;j+=i)if(l<=j&&j<=r) F[i][j-l]=1; for(int i=1;i<=m;++i){ const auto [o,x,y]=A[i]; if(o==1)F[n+i]=F[x]|F[y]; else if(o==2)F[n+i]=F[x]&F[y]; else F[n+i]=~F[x]; } for(int i=1;i<=q;++i){ const auto [x,y]=Q[i]; if(l<=y&&y<=r)ans[i]=F[x].test(y-l); } } for(int i=1;i<=q;++i) cout<<(ans[i]?"TAK\n":"NIE\n"); return 0; } /* */ |