题目链接
给了一个母串s1 和两个串s2 s3
询问s1中有多少个以s2开头s3结尾的子串 子串中s2 s3可以重叠
没啥好说的,直接哈希,先预处理以s2开头的下标和以s3结尾的下标
(string是真的方便)
然后遍历一次s1,如果当前下标满足了s2,就一直遍历下去寻找合法s3
注意形成的子串长度应当大于等于max(s2,s3) 直接存入哈希值最后去重就好了 ,最麻烦的就是哈希冲突 QAQ
最后没要模数 直接long long自然溢出就过了
当然我相信还有其他解法
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int long long
#define inf 0x3f3f3f3f
#define mods 1000000007
#define modd 998244353
#define PI acos(-1)
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define si size()
#define E exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
#define IOS ios::sync_with_stdio(false);cin.tie(0)using namespace std;ll gcd(ll a,ll b){if(a<0)a&#61;-a;if(b<0)b&#61;-b;return b&#61;&#61;0?a:gcd(b,a%b);}
template<typename T>void read(T &res){bool flag&#61;false;char ch;while(!isdigit(ch&#61;getchar()))(ch&#61;&#61;&#39;-&#39;)&&(flag&#61;true);
for(res&#61;ch-48;isdigit(ch&#61;getchar());res&#61;(res<<1)&#43;(res<<3)&#43;ch - 48);flag&&(res&#61;-res);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll qp(ll a,ll b,ll mod){ll ans&#61;1;if(b&#61;&#61;0){return ans%mod;}while(b){if(b%2&#61;&#61;1){b--;ans&#61;ans*a%mod;}a&#61;a*a%mod;b&#61;b/2;}return ans%mod;}
ll qpn(ll a,ll b, ll p){ll ans &#61; 1;a%&#61;p;while(b){if(b&1){ans &#61; (ans*a)%p;--b;}a &#61;(a*a)%p;b >>&#61; 1;}return ans%p;}
string s1,s2,s3;
ll dis;
ll len1,len2,len3;
ll vis[3][100003];
vector<ll>ans;
signed main(){
cin>>s1>>s2>>s3;
len1&#61;s1.size();
len2&#61;s2.size();
len3&#61;s3.size();
dis&#61;max(len2,len3);
for(int i&#61;0;i<len1;i&#43;&#43;){
if(s1.substr(i,len2)&#61;&#61;s2){vis[1][i]&#61;1;
}if(s1.substr(i,len3)&#61;&#61;s3){vis[2][i&#43;len3-1]&#61;1;
}}
for(int i&#61;0;i<len1;i&#43;&#43;){if(vis[1][i]){ll ve&#61;0;for(int j&#61;i;j<len1;j&#43;&#43;){ve&#61;(ve*133&#43;(s1[j]-&#39;a&#39;&#43;1));if(vis[2][j]&#61;&#61;1&&j-i&#43;1>&#61;dis){ans.pb(ve);}}}}
sort(ans.begin(),ans.end());
ans.resize(unique(ans.begin(), ans.end())-ans.begin());
printf("%d",ans.size());}