//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "后缀数组": {
        "prefix": "acm-6.6倍增",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "#define LL long long",
            "using namespace std;",
            "const int N=1e6+3;",
            "inline void in(Re &x){",
            "    int fu=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')fu|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=fu?-x:x;",
            "}",
            "struct Suffix_Array{",
            "\tint n,m,x[N],y[N],H[N],SA[N],cnt[N],rank[N],Height[N];char s[N];",
            "\t//Suf[i]: s[i,n]",
            "\tinline void get_SA(){",
            "\t\tm=128;",
            "\t\tfor(Re i=1;i<=n;++i)++cnt[x[i]=s[i]];",
            "\t\tfor(Re i=2;i<=m;++i)cnt[i]+=cnt[i-1];",
            "\t\tfor(Re i=n;i>=1;--i)SA[cnt[x[i]]--]=i;",
            "\t\tfor(Re len=1;len<=n;len<<=1){",
            "\t\t\tRe t=0;",
            "\t\t\tfor(Re i=n-len+1;i<=n;++i)y[++t]=i;",
            "\t\t\tfor(Re i=1;i<=n;++i)if(SA[i]>len)y[++t]=SA[i]-len;",
            "\t\t\t",
            "\t\t\tfor(Re i=1;i<=m;++i)cnt[i]=0;",
            "\t\t\tfor(Re i=1;i<=n;++i)++cnt[x[i]];",
            "\t\t\tfor(Re i=2;i<=m;++i)cnt[i]+=cnt[i-1];",
            "\t\t\tfor(Re i=n;i>=1;--i)SA[cnt[x[y[i]]]--]=y[i],y[i]=0;",
            "\t\t\t",
            "\t\t\tswap(x,y);",
            "\t\t\tx[SA[1]]=m=1;",
            "\t\t\tfor(Re i=2;i<=n;++i)",
            "\t\t\t\tx[SA[i]]=(y[SA[i]]==y[SA[i-1]]&&y[SA[i]+len]==y[SA[i-1]+len])?m:++m;",
            "\t\t\tif(m==n)break;",
            "\t\t}",
            "\t\tfor(Re i=1;i<=n;++i)printf(\"%d \",SA[i]);",
            "\t}",
            "\tinline void get_Height(){",
            "\t\tfor(Re i=1;i<=n;++i)rank[SA[i]]=i;",
            "\t\tfor(Re i=1,k=0;i<=n;++i){",
            "\t\t\tif(rank[i]==1)continue;",
            "\t\t\tif(k)--k;//H[i-1]-1<=H[i]",
            "\t\t\tRe j=SA[rank[i]-1];",
            "\t\t\twhile(i+k<=n&&j+k<=n&&s[i+k]==s[j+k])++k;",
            "\t\t\tHeight[rank[i]]=k;",
            "\t\t}",
            "//\t\tfor(Re i=1;i<=n;++i)printf(\"%d \",Height[i]);",
            "\t}",
            "}SA;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tscanf(\"%s\",SA.s+1),SA.n=strlen(SA.s+1);",
            "\tSA.get_SA(),SA.get_Height();",
            "}",
            ""
        ],
        "description": "插入 后缀数组"
    }
}