字符串hash
A=la+ra
B=lb+rb
存储ra+fan(la)
查询fan(lb)+rb
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef unsigned __int64 LLU;
const int N=1e6+100;
const int key=1e9,wei=10007;
#define pii pair<LLU,int>
#define fi first
#define se second
#define mk make_pair
char ss[N],tt[N];
LLU mi[N];
pii sta[N];int top;
int main(){
#ifdef DouBi
freopen("in.cpp","r",stdin);
#endif // DouBI
mi[0]=1;
for(int i=1;i<N;i++){
mi[i]=mi[i-1]*wei;
}
while(gets(ss)>0){
gets(tt);
int n=strlen(ss),m=strlen(tt);
if(n!=m){
printf("-1 -1\n");continue;
}
LLU now=0,ver=0;
top=0;
for(int i=0;i<n;i++){
now=now*wei+ss[i];
}
for(int i=n-1;i>=0;i--){
ver=ver*wei+ss[i];
now-=mi[n-1-i]*ss[i];
sta[top++]=pii(now+ver,i);
}
sort(sta,sta+top);
int ii=-1,jj=-1;
now=0,ver=0;
for(int i=n-1;i>=0;i--){
ver=ver*wei+tt[i];
}
for(int i=0;i<n-1;i++){
ver-=mi[i]*tt[i];
now=now*wei+tt[i];
int id=lower_bound(sta,sta+top,mk(now+ver,n-1-i))-sta;
if(id<top&&sta[id].fi==now+ver){
ii=n-1-i-1;jj=sta[id].se;
break;
}
}
printf("%d %d\n",ii,jj);
}
return 0;
}