设 表示
只用考虑对一个串处理
,另一个匹配是一样
假设当前在
,所有
中最大值为
,这最大的
设为
如果
,继续暴力匹配即可
否则设
,显然
是一样的
若
否则
暴力拓展即可
复杂度
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int N=20000007;
char s[N],t[N];
int n,m,z[N],anc[N];
inline void init_z(){
z[1]=n;
for(int i=2,l=0,r=0;i<=n;i++){
if(i<=r)z[i]=min(z[i-l+1],r-i+1);
while(i+z[i]<=n&&s[i+z[i]]==s[z[i]+1])z[i]++;
if(i+z[i]-1>r)l=i,r=z[i]+i-1;
}
}
inline void exkmp(){
init_z();
for(int i=1,l=0,r=0;i<=m;i++){
if(i<=r)anc[i]=min(z[i-l+1],r-i+1);
while(i+anc[i]<=m&&t[i+anc[i]]==s[anc[i]+1])anc[i]++;
if(i+anc[i]-1>r)l=i,r=anc[i]+i-1;
}
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
m=readstring(t),n=readstring(s);
exkmp();
ll res=0;
for(int i=1;i<=n;i++)res^=(ll)i*(z[i]+1);
cout<<res<<'\n';
res=0;
for(int i=1;i<=m;i++)res^=(ll)i*(anc[i]+1);
cout<<res<<'\n';return 0;
}