对每个子串暴力匹配至失配三次即可。可以用SA查lcp。然而在bzoj上被卡常了。当然也可以二分+哈希或者SAM甚至FFT。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int T,n,m,sa[N],sa2[N],rk[N<<],tmp[N<<],lg2[N],cnt[N],h[N],f[N][];
char s[N],s2[N];
void make(int n)
{
memset(cnt,,sizeof(cnt));
int m=;
for (int i=;i<=n;i++) cnt[rk[i]=s[i]]++,m=max(m,(int)s[i]);
for (int i=;i<=m;i++) cnt[i]+=cnt[i-];
for (int i=n;i>=;i--) sa[cnt[rk[i]]--]=i;
for (int k=;k<=n;k<<=)
{
int p=;
for (int i=n-k+;i<=n;i++) sa2[++p]=i;
for (int i=;i<=n;i++) if (sa[i]>k) sa2[++p]=sa[i]-k;
memset(cnt,,m+<<);
for (int i=;i<=n;i++) cnt[rk[i]]++;
for (int i=;i<=m;i++) cnt[i]+=cnt[i-];
for (int i=n;i>=;i--) sa[cnt[rk[sa2[i]]]--]=sa2[i];
memcpy(tmp,rk,sizeof(rk));
p=;rk[sa[]]=;
for (int i=;i<=n;i++)
{
if (tmp[sa[i]]!=tmp[sa[i-]]||tmp[sa[i]+k]!=tmp[sa[i-]+k]) p++;
rk[sa[i]]=p;
}
if (p==n) break;
m=p;
}
for (int i=;i<=n;i++)
{
h[i]=max(h[i-]-,);
while (s[i+h[i]]==s[sa[rk[i]-]+h[i]]) h[i]++;
}
for (int i=;i<=n;i++) f[i][]=h[sa[i]];
for (int j=;j<;j++)
for (int i=;i<=n;i++)
f[i][j]=min(f[i][j-],f[min(i+(<<j-),n)][j-]);
lg2[]=;
for (int i=;i<=n;i++)
{
lg2[i]=lg2[i-];
if ((<<lg2[i])<=i) lg2[i]++;
}
}
int query(int x,int y)
{
x=rk[x],y=rk[y];
if (x==y) return N;
if (x>y) swap(x,y);x++;
return min(f[x][lg2[y-x+]],f[y-(<<lg2[y-x+])+][lg2[y-x+]]);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj4892.in","r",stdin);
freopen("bzoj4892.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
T=read();
while (T--)
{
scanf("%s",s+);n=strlen(s+);
scanf("%s",s2+);m=strlen(s2+);
for (int i=;i<=m;i++) s[n+i]=s2[i];
make(n+m);
int ans=;
for (int i=;i<=n-m+;i++)
{
int x=i;
for (int j=;j<=&&x-i+<=m;j++)
{
x+=query(x,n+x-i+);
x++;
}
if (x-i+<=m) x+=query(x,n+x-i+);
if (x-i+>m) ans++;
}
cout<<ans<<endl;
}
return ;
}