广义后缀自动机(在线做法)

广义后缀自动机就是将后缀自动机推广到多串
有在线构造还有离线构造两种
在线的话 很多人 都是直接将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();
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值