提交时间:2022-07-19 11:55:17
运行 ID: 52341
#include <cstdio> #include <iostream> #include <cstring> using namespace std; const long long md=233; char s[1000005]; char c[1000005]; char r[1000005]; long long hs[1000005]; long long qs[1000005]; long long ans,res; long long p[1000005]; int t,a,b,n; bool chk(int k){ int i=k,flg=1,v=0; while(flg){ if((hs[i+1]*p[i]+qs[i])==ans) return true; i=(i+k)%n; if(i==k){ if(v) return false; else v=1; } } } bool slv(){ int i; hs[n+1]=0; qs[0]=0; for(i=n;i>=1;i--) hs[i]=hs[i+1]+(long long)c[i]*p[n-i]; for(i=1;i<=n;i++) qs[i]=qs[i-1]*md+(long long)c[i]; if(chk(n-(b-a))) return true; if(chk(b-a)) return true; return false; } void ycl(int k){ int i,j; for(i=1;i<=n;i++) c[i]=s[i]; for(i=1,j=k;i<j;i++,j--) swap(c[i],c[j]); } int main(){ scanf("%d",&t); int i,j; p[0]=1; for(i=1;i<=5e5;i++) p[i]=p[i-1]*md; while(t--){ scanf("%s",s+1); scanf("%s",r+1); n=strlen(s+1); scanf("%d%d",&a,&b); if(a>b) swap(a,b); ans=0; for(i=1;i<=n;i++) ans=ans*md+r[i]; for(i=1;i<=n;i++) c[i]=s[i]; if(slv()){ puts("yes"); continue; } ycl(a); if(slv()){ puts("yes"); continue; } ycl(b); if(slv()){ puts("yes"); continue; } puts("no"); } return 0; }