字典树模板

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;

typedef struct Trie{
    int v;
    Trie *next[26];
}Trie;
Trie root;
void createTrie(char *str)
{
    int len = strlen(str);
    Trie *p = &root, *q;
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        if(p->next[id] == NULL)
        {
            q = (Trie *)malloc(sizeof(root));
            q->v = 1;
            for(int j=0; j<26; ++j)
                q->next[j] = NULL;
            p->next[id] = q;
            p = p->next[id];
        }
        else
        {
            p->next[id]->v++;
            p = p->next[id];
        }
    }
}

int findTrie(char *str)
{
    int len = strlen(str);
    Trie *p = &root;
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        p = p->next[id];
        if(p == NULL)
            return 0;
    }
    return p->v;
}
void dele(char *str,int n)
{
    Trie *p = &root;
    int len = strlen(str);
    for(int i=0; i<len; ++i)
    {
        int id = str[i]-'a';
        p = p->next[id];
        p->v-=n;
    }
    for(int j=0; j<26; ++j)
    {
         p->next[j] = NULL;
    }
}
int main()
{
    int t;
    char s1[10000],s2[10000];
    for(int i=0;i<26;i++)
    {
        root.next[i]=NULL;
    }
    cin>>t;
    while(t--)
    {
        scanf("%s%s",s1,s2);
        if(s1[0]=='i')
        {
            createTrie(s2);
        }
        else if(s1[0]=='s')
        {
            int ans=findTrie(s2);
            if(ans)
            {
                puts("Yes");
            }
            else
            {
                puts("No");
            }
        }
        else
        {
            int cnt=findTrie(s2);
            if(cnt)
            {
                dele(s2,cnt);
            }
        }
    }
    return 0;
}