需要修改的后缀自动机模板

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int tot=0,e[500000][26],maxn[500000],par[500000];
int Push(int v)
{
    maxn[++tot]=v;
    return tot;
}
int a[500000],las=Push(0),root=1;
void _ins(int v)
{
    int np=Push(maxn[las]+1),p=las;
    while(p&&(!e[p][v]))e[p][v]=np,p=par[p];
    if(!p)par[np]=root;
    else{
        int q=e[p][v];
        if(maxn[p]+1==maxn[q])par[np]=q;
        else{
            int nq=Push(maxn[p]+1);
            memcpy(e[nq],e[q],sizeof(e[q]));
            par[nq]=par[q],par[q]=par[np]=nq;
            for(int t=p;t&&e[t][v]==q;t=par[t])e[t][v]=nq;
        }
    }
    las=np;
}
int main()
{
    return 0;
}

猜你喜欢

转载自blog.csdn.net/includelhc/article/details/80396513