tzzl3035 @ 2024-12-17 12:58:21
rt
#include <bits/stdc++.h>
int nex[3000003][100], num[3000003], cnt;
int main() {
auto ins = [&](std::string s) -> void {
int nod = 0;
for(int i = 0; i < s.size(); ++i) {
int c = s[i] - '0';
if(!nex[nod][c])
nex[nod][c] = ++cnt;
nod = nex[nod][c];
num[nod] += 1;
}
};
auto fin = [&](std::string s) -> int {
int nod = 0;
for(int i = 0; i < s.size(); ++i) {
int c = s[i] - '0';
if(!nex[nod][c])
return 0;
nod = nex[nod][c];
}
return num[nod];
};
int T;
std::cin >> T;
for(; T; --T) {
int n, q;
std::cin >> n >> q;
memset(nex, 0, sizeof(nex));
memset(num, 0, sizeof(num));
cnt = 0;
for(int i = 0; i < n; ++i) {
std::string s;
std::cin >> s;
ins(s);
}
for(int i = 0; i < q; ++i) {
std::string s;
std::cin >> s;
std::cout << fin(s) << '\n';
}
}
}
by kbzcz @ 2024-12-17 13:02:26
@tzzl3035 MLE不就数组开大了
by tzzl3035 @ 2024-12-17 13:17:47
@kbzcz 谢谢,我想复杂了qwq