注意字符串往往具有可二分性(子串具有母串的性质)
https://ac.nowcoder.com/acm/contest/9984/B
#include <bits/stdc++.h>
using namespace std;
const int Mn = 2e5 + 5;
#define ull unsigned long long
#define ll long long
char s[Mn],t[Mn];
ull hs[Mn],ht[Mn];
const ull base = 131;
ull b[Mn];
int main(){
b[0] = 1;
for(int i = 1;i <= Mn - 5;i ++){
b[i] = b[i - 1] * base;
}
scanf("%s%s",s + 1,t + 1);
int ls = strlen(s + 1),lt = strlen(t + 1);
for(int i = 1;i <= ls;i ++) hs[i] = hs[i - 1] * base + s[i] - 'a' + 1;
for(int i = 1;i <= lt;i ++) ht[i] = ht[i - 1] * base + t[i] - 'a' + 1;
ll ans = 0,res = 0;
for(int i = 1;i <= lt;i ++){
if(s[i] != t[i]) break;
ll l = i,r = lt,mid;
ans = 0;
while(l <= r){
mid = (l+r) >>1;
if(hs[mid - i] + hs[i] * b[mid - i] == ht[mid]){
ans = max(ans,mid - i);
l = mid + 1;
}else r = mid - 1;
}
res += ans;
}printf("%lld",res);
return 0;
}