//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",
            "using namespace std;",
            "const int N=5e5+5;",
            "char s[N];",
            "inline void in(Re &x){",
            "    Re f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "struct Palindromic_Automaton{",
            "\tint O,last,siz[N],cnt[N],len[N],fail[N],trans[N][26];",
            "\tPalindromic_Automaton(){O=1,len[1]=-1,fail[0]=fail[1]=last=1;}",
            "\t// 0:偶数回文的根节点",
            "\t// 1:奇数回文的根节点",
            "\tinline int find(Re p,Re id){while(s[id-1-len[p]]!=s[id])p=fail[p];return p;}",
            "\tinline void insert(Re ch,Re id){",
            "\t\tRe cur=find(last,id),now=trans[cur][ch];",
            "\t\tif(!now){",
            "\t\t\tnow=++O,len[now]=len[cur]+2;",
            "\t\t\tfail[now]=trans[find(fail[cur],id)][ch];",
            "\t\t\tcnt[now]=cnt[fail[now]]+1;",
            "\t\t\ttrans[cur][ch]=now;",
            "\t\t}",
            "\t\t++siz[now],last=now;",
            "\t}",
            "\tinline void sakura(){",
            "\t\tfor(Re i=O;i>=2;--i)siz[fail[i]]+=siz[i];",
            "\t}",
            "}PAM;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tscanf(\"%s\",s+1);",
            "\tfor(Re i=1,k=0;s[i];++i){",
            "\t\ts[i]=(s[i]-'a'+k)%26+'a';",
            "\t\tPAM.insert(s[i]-'a',i);",
            "\t\tprintf(\"%d \",k=PAM.cnt[PAM.last]);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 回文自动机"
    }
}