Skip to content

Commit b46db8b

Browse files
Update stringmultimatching.cpp
1 parent d3227c4 commit b46db8b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Kattis/open/stringmultimatching.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int n;
66
string s;
77

88
struct autoac {
9-
int sl[mxN+1], ol[mxN+1], sz=1, c[mxN+1][256], d[mxN+1][256], qu[mxN+1];
9+
int sl[mxN+1], ol[mxN+1], sz=1, c[mxN+1][256], d[mxN+1][256];
1010
vector<int> oc[mxN];
1111
vector<array<int, 2>> no[mxN+1];
1212
void add(string s, int i) {
@@ -20,20 +20,17 @@ struct autoac {
2020
no[u].push_back({i, s.size()});
2121
}
2222
void ac() {
23-
sl[0]=-1;
24-
int qt=0;
25-
qu[qt++]=0;
26-
for(int qh=0; qh<qt; ++qh) {
27-
int u=qu[qh];
23+
for(queue<int> q({0}); q.size(); q.pop()) {
24+
int u=q.front();
25+
if(!ol[u])
26+
ol[u]=ol[sl[u]];
2827
for(int a=0; a<256; ++a) {
2928
int v=c[u][a], w=sl[u];
30-
d[u][a]=v?v:(u?d[w][a]:0);
31-
if(!v)
32-
continue;
33-
sl[v]=u?d[w][a]:0;
34-
if(!ol[v])
35-
ol[v]=ol[sl[v]];
36-
qu[qt++]=v;
29+
if(v) {
30+
sl[v]=d[w][a];
31+
q.push(v);
32+
}
33+
d[u][a]=v?v:d[w][a];
3734
}
3835
}
3936
}
@@ -70,7 +67,7 @@ int main() {
7067
memset(ac.sl, 0, 4*ac.sz);
7168
memset(ac.ol, 0, 4*ac.sz);
7269
memset(ac.c, 0, sizeof(ac.c[0])*ac.sz);
73-
memset(ac.d, 0, sizeof(ac.d[0])*ac.sz);
70+
memset(ac.d, 0, sizeof(ac.d[0]));
7471
for(int i=0; i<ac.sz; ++i)
7572
ac.no[i].clear();
7673
ac.sz=1;

0 commit comments

Comments
 (0)