baoli qiutiao QwQ
查看原帖
baoli qiutiao QwQ
246331
mystic_qwq楼主2024/10/28 15:37
#include<bits/stdc++.h>
using namespace std;
#define int long long
using PII=pair<int,int>;
#define File(str) \
    freopen(str".in","r",stdin);\
    freopen(str".out","w",stdout)
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define irep(i,x,y) for(int i=x;i>=y;--i)
#define Set(x,y) memset(x,y,sizeof(x))
#define fi first
#define se second
#define pb push_back
#define PQ priority_queue
#define TLC (double)clock()/CLOCKS_PER_SEC<0.91
//#define add(u,v) G[u].pb(v)
#define W while
#define Dbg(fmt,...) \
    fprintf(stderr,"%s %d %s: " fmt "\n",\
    __FILE__,__LINE__,__FUNCTION__,##__VA_ARGS__)
void smin(int&a,int b){a=min(a,b);}
void smax(int&a,int b){a=max(a,b);}
const int N=2010,Mod=1e9+7,V=2e5+10;
/*
n people jil.
each has work bank Si
choose a substring len [2,k] in Si as his word
if not 1st round, need to start with last round's last element
else start with element 1
q queries, each ask jil r times, end with element c,is ok or not.

dp(k,x): in the kth round,
is it able to end up with card x(each has a belonging).
dp(k,x)= cup ( [bely!=belx] and
    [Sy in S(max(l[bel_x],x-k+1)..x-1)] ) dp(k-1,y)
*/
int n,K,q,tot,L[N],a[N],R[N],bel[N];
bool dp[110][N];
vector<int> G[V];
bool in(int x,int l,int r){
    rep(i,l,r)if(a[i]==x)return 1;
    return 0;
}
void Init(){
    Set(L,0),Set(R,0),Set(bel,0),Set(dp,0),Set(a,0);
    cin>>n>>K>>q;
    tot=0;
    rep(i,1,n){
        int l;
        L[i]=tot+1;
        cin>>l;
        while(l--)cin>>a[++tot],bel[tot]=i,G[a[tot]].pb(tot);
        R[i]=tot;
    }
}
void Solve(){
    Init();
    rep(i,1,tot)
        if(a[i]==1){
            for(int j=i+1;j<=R[bel[i]];++j)
                dp[1][j]=1;
            i=R[bel[i]];
        }
    rep(i,2,100){
        rep(j,1,tot)
            rep(k,1,tot)
                if(dp[i-1][k]&&bel[j]!=bel[k]&&in(a[k],max(L[bel[j]],j-K+1),j-1)){
                    dp[i][j]=1;
                    break;
                }
    }
    W(q--){
        int r,c;
        cin>>r>>c;
        for(int x:G[c]){
            if(dp[r][x]){
                cout<<"1\n";
                goto End;
            }
        }
        cout<<"0\n";
        End:;
    }
}
main(){
    cin.tie(0)->sync_with_stdio(0);
    int T=1;
    cin>>T;
    while(T--)
        Solve();
}

2024/10/28 15:37
加载中...