#include<iostream> #include <algorithm> #include <cstring> using namespace std; const int N=3e6; int a[N],n,m,ch[N][2],tot; int val[N],ed[N]; void insert(int len){ int u=1; for(int i=1;i<=len;i++){ int c=a[i]; if(ch[u][c]==0) ch[u][c]=++tot; u=ch[u][c]; val[u]++; } ed[u]++; } void find(int len){ int i,fg=1; int u=1,ans=0; for(i=1;i<=len;i++){ if(ch[u][a[i]]==0){ fg=0; break;} u=ch[u][a[i]]; ans+=ed[u]; } if(fg) ans+=val[u]-ed[u]; printf("%d\n",ans); } main(){ int ts,i,j; //cin.tie(0);cout.tie(0); tot=1; cin>>n>>m; for(i=1;i<=n;i++){ cin>>ts; for(j=1;j<=ts;j++) scanf("%d",a+j); insert(ts); } for(i=1;i<=m;i++){ cin>>ts; for(j=1;j<=ts;j++) scanf("%d",a+j); find(ts); } }
标签:int,ybt,ts,Secret,1476,include From: https://www.cnblogs.com/towboa/p/16944337.html