//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "Trie树": {
        "prefix": "acm-6.3前缀统计",
        "body": [
            "#include<cstring>",
            "#include<cstdio>",
            "#define R register int",
            "using namespace std;",
            "const int SP=500003;",
            "int trie[SP][26],pan[SP],ed[SP],re,t=1,n,m;char ch[55];",
            "inline void add(char ch[]){",
            "    R a,i=0,p=1,l=strlen(ch);",
            "    for(;i<l;i++){",
            "        a=ch[i]-'a';",
            "        if(!trie[p][a])trie[p][a]=++t;",
            "        p=trie[p][a];",
            "    }",
            "    ++ed[p];",
            "}",
            "inline int find(char ch[]){",
            "    R i=0,p=1,ans=0,l=strlen(ch);",
            "    for(;i<l;i++){",
            "        p=trie[p][ch[i]-'a'];",
            "        ans+=ed[p];",
            "        if(!p)return ans;",
            "    }",
            "    return ans;",
            "}",
            "int main(){",
            "    scanf(\"%d%d\",&n,&m);",
            "    while(n--){scanf(\"%s\",ch);add(ch);}",
            "    while(m--){scanf(\"%s\",ch);printf(\"%d\\n\",find(ch));}",
            "}",
            ""
        ],
        "description": "插入 Trie树"
    }
}