显示代码纯文本
#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
const int maxn = 1e5*20;
inline int read() {
int x = 0, f = 1; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
return x * f;
}
char s[maxn];
int len, n, m;
struct Trie {
int ch[maxn][27], siz, vis[maxn];
Trie () {
siz = 1;
memset(ch[0], 0, sizeof ch[0]);
memset(vis, 0, sizeof vis);
}
inline int id(char c) {
return c - 'a';
}
void Build_Trie() {
int num = 0;
for(rint i = 0; i < len; ++i) {
int pos = id(s[i]);
if(!ch[num][pos]) {
memset(ch[siz], 0, sizeof ch[siz]);
ch[num][pos] = siz++;
}
num = ch[num][pos];
}
vis[num] = 1;
}
inline bool Query_Trie(rint l, rint num) {
if(l == len) return vis[num];
int pos = id(s[l]);
if(s[l] == '*') {
for(rint i = 0; i < 26; ++i)
if(ch[num][i])
if(Query_Trie(l + 1, ch[num][i])) return 1;
return 0;
}
if(!ch[num][pos]) return 0;
return Query_Trie(l + 1, ch[num][pos]);
}
}trie;
inline int _main() {
freopen("asm_talk.in", "r", stdin); freopen("asm_talk.out", "w", stdout);
n = read();
for(rint i = 1; i <= n; ++i) {
m = read(); scanf("%s", s); getchar(); len = strlen(s);
if(m == 1) trie.Build_Trie();
else {
if(trie.Query_Trie(0, 0)) puts("YES\n");
else puts("NO\n");
}
}
return 0;
}
int jiasu = _main();
int main(){;}