提交时间:2022-07-19 12:37:43

运行 ID: 52524

#include <bits/stdc++.h> using namespace std; const int N=5e5+5; int t; int a[N],b[N]; int n; int l,r; void init() { n=0; char ch=getchar(); while(ch<'a'||ch>'z') ch=getchar(); while(ch>='a'&&ch<='z') { a[++n]=ch-'a'; ch=getchar(); } while(ch<'a'||ch>'z') ch=getchar(); for(int i=1; i<=n; i++) { b[i]=ch-'a'; ch=getchar(); } scanf("%d%d",&l,&r); return ; } int dfs(int x) { if(a[x]!=b[1]) return 0; for(int i=n; i>1; i--) { int j=(x+i-1); if(j>n) j=j-n; if(a[j]!=b[i]) return 0; } return 1; } int tag[N]; void sol() { r=r-l; for(int i=1; i<n; i++) { if(tag[(i*r)%n+1]) { printf("yes\n"); return ; } if(tag[((n-i)*r)%n+1]) { printf("yes\n"); return ; } } printf("no\n"); return ; } void swaps(int l,int r) { int mid=(l+r)/2; for(int i=l; i<=mid; i++) swap(a[i],a[r+l-i]); } void tips() { swaps(1,l); swaps(l+1,n); for(int i=1; i<=n; i++) if(dfs(i)) tag[i]=1; swaps(1,l); swaps(l+1,n); swaps(1,r); swaps(r+1,n); for(int i=1; i<=n; i++) if(dfs(i)) tag[i]=1; } int main() { scanf("%d",&t); for(int T=1; T<=t; T++) { init(); for(int i=1; i<=n; i++) tag[i]=dfs(i); tips(); sol(); } return 0; }