/*
LuoguP2992
同时维护01字典树每个节点经过的次数
以及用f[N]对结尾标记
*/#include<iostream>#include<algorithm>#include<cstdio>usingnamespace std;inlineintread(){int x =0, op =1;char ch =getchar();while(!isdigit(ch)){if(ch =='-') op =-1; ch =getchar();}while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48), ch =getchar();}return x * op;}constint N =5e5+10;int ch[N][2], cnt[N], f[N];int tot =1;inlinevoidinsert(int* p,int len){int u =1;for(int i =0; i < len;++i){int v = p[i];if(!ch[u][v]){
ch[u][v]=++tot;}
u = ch[u][v];
cnt[u]++;}
f[u]++;}intquery(int* p,int count){int u =1, res =0;for(int i =0; i < count;++i){int v = p[i];if(ch[u][v]==0)return res;
u = ch[u][v];
res += f[u];}return res + cnt[u]- f[u];}int b[10005];intmain(int argc,charconst*argv[]){int m =read(), n =read();for(int i =0, k; i < m;++i){
k =read();for(int j =0; j < k;++j){
b[j]=read();}insert(b, k);}for(int i =0, k; i < n;++i){
k =read();for(int j =0; j < k;++j){
b[j]=read();}printf("%d\n",query(b, k));}return0;}
code/*LuoguP2992同时维护01字典树每个节点经过的次数以及用f[N]对结尾标记 */#include <iostream>#include <algorithm>#include <cstdio>using namespace std;inline int read(){ int x = 0, op = 1; char ch = getchar(); while (!isdigit(ch)){ if (ch == '-