@[yzkadbq_qwq](/user/573334) j循环里面a[j]写成a[i]了
by liuxy1234 @ 2023-05-16 19:37:35
AC了,此帖结
by yzkadbq_qwq @ 2023-05-16 19:43:08
@[yzkadbq_qwq](/user/573334) all和cnt的加减很神奇,直接给你改过的代码吧。
```cpp
#include<bits/stdc++.h>
using namespace std;
struct trie{
int cnt,son[2],all;
} ch[5000001];
int top=0,n,m;
void ins(bool a[],int len){
int p=0;
for(int i=1;i<=len;i++){
ch[p].all++;
if(!ch[p].son[a[i]]) ch[p].son[a[i]]=++top;
p=ch[p].son[a[i]];
}
ch[p].cnt++;
return;
}
int query(bool a[],int len){
int p=0,ans=0;
for(int i=1;i<=len;i++){
ans+=ch[p].cnt;
if(!ch[p].son[a[i]]) return ans;
p=ch[p].son[a[i]];
}
return ans + ch[p].cnt+ch[p].all;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int len;
cin>>len;
bool a[len+1];
for(int j=1;j<=len;j++){
int tmp;
cin>>tmp;
if(tmp){
a[j]=1;
}else{
a[j]=0;
}
}
ins(a,len);
}
for(int i=1;i<=m;i++){
int len;
cin>>len;
bool a[len+1];
for(int j=1;j<=len;j++){
int tmp;
cin>>tmp;
if(tmp){
a[j]=1;
}else{
a[j]=0;
}
}
cout<<query(a,len)<<"\n";
}
return 0;
}
```
by liuxy1234 @ 2023-05-16 19:43:42