题目链接
序列自动机预处理一下原串。
然后直接序列自动机上处理询问即可。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
#define fi first
#define se second
#define pb push_back
char a[N],b[N];
int x,nx[N][26];
int main() {
ios::sync_with_stdio(false);
cin>>a+1;
int x=strlen(a+1);
for(int i=x;i>=1;i--){
for(int j=0;j<26;j++)nx[i][j]=nx[i+1][j];
nx[i][a[i]-'a']=i;
}
cin>>x;
for(int i=1;i<=x;i++){
cin>>b+1;
int y=strlen(b+1);
int z=0,ok=0;
for(int j=1;j<=y;j++){
if(!nx[z+1][b[j]-'a']){
ok=1;break;
}
z=nx[z+1][b[j]-'a'];
}
if(ok)cout<<"No\n";
else cout<<"Yes\n";
}
return 0;
} 
京公网安备 11010502036488号