编辑
2025-08-30
XCPC
00
请注意,本文编写于 141 天前,最后修改于 141 天前,其中某些信息可能已经过时。
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int M = 3e6 + 5, mod = 1e9 + 7; int tr[M][66], cnt[M], tot; int getnum(char x) { if (x >= 'A' && x <= 'Z') return x - 'A'; else if (x >= 'a' && x <= 'z') return x - 'a' + 26; else return x - '0' + 52; } void insert(string s) { int now = 0; for (auto x : s) { if (!tr[now][getnum(x)]) { tr[now][getnum(x)] = ++tot; } now = tr[now][getnum(x)]; cnt[now]++; } } int query(string s) { int now = 0; for (auto x : s) { if (!tr[now][getnum(x)]) { return 0; } now = tr[now][getnum(x)]; } return cnt[now]; } void solve() { tot = 0; int n, q; cin >> n >> q; while (n--) { string s; cin >> s; insert(s); } while (q--) { string s; cin >> s; cout << query(s) << endl; } for (int i = 0; i <= tot; i++) { cnt[i] = 0; for (int j = 0; j < 66; j++) tr[i][j] = 0; } } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t = 1; cin >> t; while (t--) solve(); return 0; }
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay