ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200508 | #2422. 名字 | tkswls | 100 | 1691ms | 14624kb | C++11 | 1.8kb | 2024-01-04 11:08:25 | 2024-01-04 12:07:36 |
answer
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int son[200005][30], cnt, ed[200005], n, fail[200005], ans, u, num[200005], maxa, in[200005], a[1005][1005], m, inn[200005];
string moshi[1005];
string s;
queue<int> que;
void add(int op) {
int w = 0;
for (int i = 0; i < moshi[op].length(); i++) {
if (son[w][moshi[op][i] - 'a'] != 0) {
w = son[w][moshi[op][i] - 'a'];
} else {
son[w][moshi[op][i] - 'a'] = ++cnt;
w = cnt;
}
}
ed[op] = w;
}
void build() {
queue<int> q;
for (int i = 0; i < 26; i++) {
if (son[0][i] != 0) {
q.push(son[0][i]);
}
}
while (q.size()) {
int p = q.front();
q.pop();
for (int i = 0; i < 26; i++) {
if (son[p][i] != 0) {
fail[son[p][i]] = son[fail[p]][i];
q.push(son[p][i]);
} else {
son[p][i] = son[fail[p]][i];
}
}
}
}
inline void topo() {
for (int i = 0; i <= cnt; i++) inn[i] = in[i];
while (que.size()) que.pop();
for (int i = 0; i <= cnt; i++) {
if (!inn[i]) que.push(i);
}
int u;
while (que.size()) {
u = que.front();
num[fail[u]] += num[u];
inn[fail[u]]--;
que.pop();
if (inn[fail[u]] == 0) {
que.push(fail[u]);
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> moshi[i];
add(i);
}
build();
for (int i = 1; i <= cnt; i++) {
in[fail[i]]++;
}
for (int i = 1; i <= n; i++) {
memset(num, 0, sizeof(num));
u = 0;
for (int j = 0; j < moshi[i].size(); j++) {
u = son[u][moshi[i][j] - 'a'];
num[u]++;
}
topo();
for (int j = 1; j <= n; j++) {
a[j][i] = num[ed[j]] + a[j][i - 1];
}
}
int p, q, w;
for (int i = 1; i <= m; i++) {
cin >> p >> q >> w;
cout << a[w][q] - a[w][p - 1] << "\n";
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 2140kb
input:
10 100 bc a aaa aaaccaaaca caaabacbcaaaaccaaaaaccaaacaccaaaa aaabacacbccbccaaabacbc accaaaa aaaccaaa...
output:
12 0 1 48 7 0 56 1 15 3 1 1 49 46 11 18 4 5 13 45 1 4 32 18 1 1 7 10 0 18 1 5 1 1 1 4 53 55 1 24 4 1...
result:
ok 100 lines
Test #2:
score: 10
Accepted
time: 1ms
memory: 2112kb
input:
5 100 ejmljknnjeldejmljknje ldejmljknnjeldejmljknnjfldejmlj jmkjknjeld fldejmljknnjeldejmljknjeldejm...
output:
6 5 1 7 10 5 8 2 6 6 3 8 4 5 4 1 5 4 9 5 7 3 6 5 4 9 5 4 5 3 5 9 9 8 10 5 1 4 3 2 8 4 4 1 1 8 7 5 4 ...
result:
ok 100 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 2384kb
input:
50 1000 aaacaaaabaaaaaaa a aaaacaaaabaaaaaaaabaaaa aaaaaaaaacaaaabaaaaaaaabaaaaaaaaaaa acbbaaabacaaa...
output:
129 77 0 21 274 11 72 109 26 7 284 18 173 19 349 8 15 5 27 6 51 311 39 371 1 3 44 6 12 492 323 346 3...
result:
ok 1000 lines
Test #4:
score: 10
Accepted
time: 3ms
memory: 2308kb
input:
30 1000 mgenjcfodhnmgenjcfodhnm genjcfodhnmgenjcfodhnmgenjcfodhnmenjcfodhnmgenjcfodhnmenjcfodhnmgenj...
output:
23 10 77 28 11 25 40 8 56 41 15 0 2 39 2 52 79 4 60 4 10 40 20 84 82 8 0 4 42 24 6 68 23 3 7 10 77 4...
result:
ok 1000 lines
Test #5:
score: 10
Accepted
time: 272ms
memory: 11124kb
input:
500 100000 bcabcbbbcacaabccbccacaccbcacbccccbbaaabbabcbcccaababccbcabcbbbcacaabccbccacaccbcacb cccbb...
output:
14 3954 226 633 528 2614 257 53 440 148 2144 768 268 17 284 185 234 30 481 495 202 0 1338 1694 4910 ...
result:
ok 100000 lines
Test #6:
score: 10
Accepted
time: 320ms
memory: 12380kb
input:
500 100000 ehecbhadefejeehecehecbhadefejeehecehecbhadefejeehecehecbhadefejeehecehecbhadefejeehecehec...
output:
251 669 335 2013 1080 23 196 450 4697 1291 35 32 1332 9 45 877 723 1340 327 138 225 218 376 194 48 1...
result:
ok 100000 lines
Test #7:
score: 10
Accepted
time: 157ms
memory: 13788kb
input:
200 100000 cefdicgefchdcbbfabajbdhcga efchcgacfahcgacfaaicfbhihciadedhacafcefdicgefchcgacfahcgacfaai...
output:
6 150 1 380 125 482 75 560 7 180 13 0 134 41 5 599 299 6 23 108 0 171 212 220 39 136 9 62 100 132 8 ...
result:
ok 100000 lines
Test #8:
score: 10
Accepted
time: 309ms
memory: 12136kb
input:
500 100000 qhyovpqmdmxzpedsswqrydaogpfjitkxfowgmxglflchcnxzjkcfqhylvpqmdmxzpedsswqrydaogpfjitkxfowgm...
output:
206 393 721 78 191 1162 84 3302 1404 918 31 57 62 234 27 150 2744 1260 88 71 193 208 1437 853 2093 4...
result:
ok 100000 lines
Test #9:
score: 10
Accepted
time: 174ms
memory: 14624kb
input:
200 100000 jjidrjrmjjhkrxsraaaqduplrcznisidrjrmjjidxjrmjjrxsraaaqaaqduslrcznisidrjrmjjidrjrmjjhkrxsr...
output:
6 390 975 291 3 136 6 264 160 125 98 1794 1 17 493 0 2 310 40 1589 11 3 81 146 13 450 5 216 11 66 43...
result:
ok 100000 lines
Test #10:
score: 10
Accepted
time: 455ms
memory: 11844kb
input:
1000 100000 cbabbcbbbbcbbbccacbabbcbbbbcbbbccacbabbcbbbbcbbbccacbabbcbbbbcbbbccacbabbcbb bccacb babb...
output:
23 3036 159 187 11472 909 2 257 173 96 1070 21215 459 920 2680 7901 17396 513 3992 1460 31684 4245 2...
result:
ok 100000 lines
Extra Test:
score: 0
Extra Test Passed