广义后缀自动机就是将后缀自动机推广到多串
有在线构造还有离线构造两种
在线的话 很多人 都是直接将last 置为1
没有加特判 很多情况是没事的 但是就是有问题 比如就不能直接“基数排序”进行递推了
加了特判的是没事的
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define inf 1ll<<62
#define endl "\n"
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define de_bug(x) cerr << #x << "=" << x << endl
#define all(a) a.begin(),a.end()
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define der(i,a,b) for(int i=a;i>=b;i--)
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int n, m , k;
string s;
string t;
struct node {
int len, fa;
int son[26];
} tr[N * 2];
int cnt = 1;
int last = 1;
int f[N * 2];
int c[N * 2];
int q[N * 2];
void extend (int c) {
if(tr[last].son[c]) {
int p = last;
int q = tr[last].son[c];
if(tr[p].len + 1 == tr[q].len)last = q;
else {
int nq = last = ++cnt;
tr[nq] = tr[q];
tr[nq].len = tr[p].len + 1;
tr[q].fa = nq;
for(; p && tr[p].son[c] == q; p = tr[p].fa) tr[p].son[c] = nq;
}
} else {
int p = last, np = last = ++cnt;
f[cnt] = 1;
tr[np].len = tr[p].len + 1;
for(; p && !tr[p].son[c]; p = tr[p].fa) tr[p].son[c] = np;
if(!p) tr[np].fa = 1;
else {
int q = tr[p].son[c];
if(tr[q].len == tr[p].len + 1)tr[np].fa = q;
else {
int nq = ++cnt;
tr[nq] = tr[q];
tr[nq].len = tr[p].len + 1;
tr[q].fa = tr[np].fa = nq;
for(; p && tr[p].son[c] == q; p = tr[p].fa) tr[p].son[c] = nq;
}
}
}
}
void jishusort() {
for(int i = 1; i <= cnt; i++)c[i] = 0;
for(int i = 1; i <= cnt; i++) c[tr[i].len]++;
for(int i = 1; i <= cnt; i++) c[i] += c[i - 1];
for(int i = 1; i <= cnt; i++) q[c[tr[i].len]--] = i;
}
void solve() {
}
int main() {
IOS;
int _ = 1;
//cin>>_;
while( _-- )
solve();
}