Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
52577 | jr_zlw | 修复符文 | C++ | 通过 | 100 | 48 MS | 16116 KB | 2581 | 2022-07-19 13:24:21 |
#include<cstdio> #include<cstring> #define rep(a,b,c) for(int c(a);c<=(b);++c) #define drep(a,b,c) for(int c(a);c>=(b);--c) const int M1=998244353,M2=1e9+7,N=5e5+10,B=29; inline int qpow(int a,int b,int M){int r(1);while(b)b&1?r=1ll*r*a%M:0ll,a=1ll*a*a%M,b=b>>1;return r; } struct hs { int x1,x2;inline hs(int x=0,int y=0){x1=x;x2=y;} inline hs operator + (const hs &Q)const{int X1=x1+Q.x1,X2=x2+Q.x2;X1>=M1?X1-=M1:0;X2>=M2?X2-=M2:0;return hs(X1,X2);} inline hs operator - (const hs &Q)const{int X1=x1-Q.x1,X2=x2-Q.x2;X1<0?X1+=M1:0;X2<0?X2+=M2:0;return hs(X1,X2);} inline hs operator + (const int &x)const {return hs(x1,x2)+hs(x,x);} inline hs operator - (const int &x)const {return hs(x1,x2)-hs(x,x);} inline hs operator * (const hs &Q)const{return hs(1ll*x1*Q.x1%M1,1ll*x2*Q.x2%M2);} inline hs operator * (const int &x)const {return hs(1ll*x1*x%M1,1ll*x2*x%M2);} inline bool operator == (const hs&Q)const{return x1==Q.x1&&x2==Q.x2;} }s[N],p[N],iv[N],pw[N],t;int a,b,n,d;char S[N],T[N];bool vis[N]; inline hs Gh(int l,int r){return (p[r]-p[l-1])*iv[l-1];} inline hs Gi(int l,int r){return (s[l]-s[r+1])*iv[n-r];} inline bool work(int a,int c) { if(a<=c) { hs s1=Gi(1,n-c),s2=Gi(n-c+1,n-(c-a)),s3=Gi(n-(c-a)+1,n); // printf("work1 %d %d :: [%d,%d] [%d,%d] [%d,%d]\n",a,c,1,n-c,n-c+1,n-c+a,n-c+a+1,n); return (s2+s1*pw[a]+s3*pw[n-c+a])==t; } else { hs s1=Gi(1,a-c),s2=Gi(a-c+1,n-c),s3=Gi(n-c+1,n),ss=s1+s3*pw[a-c]+s2*pw[a]; // printf("work2 %d %d :: [%d,%d] [%d,%d] [%d,%d]\n",a,c,1,a-c,a-c+1,n-c,n-c+1,n); // printf("QAQ :: (%d,%d) (%d,%d) (%d,%d) --> (%d,%d)\n",s1.x1,s1.x2,s2.x1,s2.x2,ss.x1,ss.x2,t.x1,t.x2); return (s1+s3*pw[a-c]+s2*pw[a])==t; } } inline void Solve() { scanf("%s%s%d%d",S+1,T+1,&a,&b); n=strlen(S+1);if(int(strlen(T+1))!=n){puts("no");return;} t=hs(0,0);rep(1,n,i)t=pw[i]*(T[i]-'a'+1)+t,p[i]=pw[i]*(S[i]-'a'+1)+p[i-1]; if(p[n]==t){puts("yes");return;}if(a>b){int tmp=a;a=b;b=tmp;}d=b-a; s[n+1]=hs(0,0);drep(n,1,i)s[i]=pw[n-i+1]*(S[i]-'a'+1)+s[i+1]; memset(vis,0,(n+3));int c=0; while(!vis[c]) { // printf("jud %d\n",c); if((Gh(n-c+1,n)+Gh(1,n-c)*pw[c])==t){puts("yes");return;} if(work(a,c)||work(b,c)){puts("yes");return;}vis[c]=true;c+=d;c>=n?c-=n:0; // return; } puts("no");return; } int main() { // freopen("runes.in","r",stdin); // freopen("runes.out","w",stdout); const int W=5e5+3;pw[0]=hs(1,1);rep(1,W,i)pw[i]=pw[i-1]*B; iv[W]=hs(qpow(pw[W].x1,M1-2,M1),qpow(pw[W].x2,M2-2,M2));drep(W,1,i)iv[i-1]=iv[i]*B; int T;scanf("%d",&T);while(T--)Solve(); }