提交时间:2022-07-19 12:00:03
运行 ID: 52362
#include<bits/stdc++.h> #define I using #define love namespace #define Elaina std I love Elaina; const int N=500010; int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); } return x*f; } int T,n,a,b,g; char s1[N],s2[N],s3[N],s4[N]; unsigned long long hs1[N],hs2[N],hs3[N],hs4[N],bit[N],tmp; bool flag; unsigned long long gethash(unsigned long long *hs,int l,int r){ return hs[r]-hs[l-1]*bit[r-l+1]; } int main(){ bit[0]=1; for(int i=1;i<=500000;i++)bit[i]=131ull*bit[i-1]; T=read(); while(T--){ scanf("%s%s",s1+1,s2+1); a=read(),b=read(); if(strlen(s1+1)!=strlen(s2+1)){ puts("no"); continue; } n=strlen(s1+1); if(a<b)swap(a,b); g=__gcd(a-b,n),flag=0; for(int i=1;i<=n;i++)s3[i]=s4[i]=s1[i]; reverse(s3+1,s3+b+1),reverse(s3+b+1,s3+n+1),reverse(s4+1,s4+a+1),reverse(s4+a+1,s4+n+1); for(int i=1;i<=n;i++)hs1[i]=131ull*hs1[i-1]+s1[i]; for(int i=1;i<=n;i++)hs2[i]=131ull*hs2[i-1]+s2[i]; for(int i=1;i<=n;i++)hs3[i]=131ull*hs3[i-1]+s3[i]; for(int i=1;i<=n;i++)hs4[i]=131ull*hs4[i-1]+s4[i]; if(hs1[n]==hs2[n]||hs3[n]==hs2[n]||hs4[n]==hs2[n]){ puts("yes"); continue; } for(int i=g;i<n;i+=g){ tmp=gethash(hs1,i+1,n)*bit[i]+hs1[i]; if(tmp==hs2[n]){ flag=1; break; } tmp=gethash(hs1,n-i+1,n)*bit[n-i]+hs1[n-i]; if(tmp==hs2[n]){ flag=1; break; } tmp=gethash(hs3,i+1,n)*bit[i]+hs3[i]; if(tmp==hs2[n]){ flag=1; break; } tmp=gethash(hs4,n-i+1,n)*bit[n-i]+hs4[n-i]; } puts(flag?"yes":"no"); } return 0; }