1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n, l, m; string s; int tot = 2; int t[500000][30]; int cnt[500000][51]; void add(string s, int idx) { int h = 1; for (char c : s) { int si = c - 'a'; if (t[h][si] <= 0) { t[h][si] = tot; tot++; } h = t[h][si]; } cnt[h][idx / 20] |= (1 << (idx % 20)); return; } void query(string s) { int h = 1; int sum = 0; for (char c : s) { int si = c - 'a'; if (t[h][si] <= 0) { return; } h = t[h][si]; } for (int i = 0; i * 20 <= n; i++) { for (int j = 0; i * 20 + j <= n && j < 20; j++) { if (cnt[h][i] & (1 << j)) { cout << i * 20 + j << ' '; } } } return; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { cin >> l; for (int j = 0; j < l; j++) { cin >> s; add(s, i); } } cin >> m; for (int i = 0; i < m; i++) { cin >> s; query(s); cout << endl; } return 0; }
- 1
信息
- ID
- 1184
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者