hellocccl @ 2024-11-08 11:59:47
//ALL IN
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
// #define int long long
#define double long double
const int N=3e6+7;
const int mod=1e9+7;
const int inf=4e18;
int a[N];
int ch[N][100];
string s;
int idx;
int cnt[N];
void insert(){
int p=0;//p为当前节点
for(int i=0;i<s.size();i++){
int j=s[i]-'a';
//插入儿子
if(!ch[p][j])ch[p][j]=++idx;
p=ch[p][j];
cnt[p]++;
}
}
int query(string s){
int p=0;
for(int i=0;i<s.size();i++){
int j=s[i]-'a';
if(!ch[p][j])return 0;
p=ch[p][j];
}
return cnt[p];
}
void solve(){
int n,q;cin>>n>>q;
int len=0;
for(int i=1;i<=n;i++){
cin>>s;
len+=s.size();
insert();
}
while(q--){
string t;cin>>t;
int ans=query(t);
cout<<ans<<'\n';
}
for(int i=0;i<=idx;i++)cnt[i]=0;
for(int i=0;i<=idx;i++){
for(int j=0;j<=66;j++){
ch[i][j]=0;
}
}
idx=0;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
cin>>_;
while(_--)solve();
}
by l1754002917 @ 2024-11-08 12:35:34
题目有大小写字母和数字 -'a'会有负数下标