1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define ff(i,j,k) for(int i=(j),end_i=(k);i< end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } #define CASET fo(___,1,read()) const int N=100010; const int S=26; const ll mod=998244853; const ll base=29; ll p[N]; int pos[N]; namespace PAM{ int s[N],n; int fa[N],ne[N][S],len[N],siz,las; int f[N][20]; ll h[N]; vector<int> adj[N]; void init() { fo(i,1,n) s[i]=0; s[n=0]=-1; fo(i,0,siz) memset(ne[i],0,sizeof(ne[i])),fa[i]=len[i]=0,adj[i].clear(); siz=1; las=0; fa[0]=1; len[1]=-1; } inline int getfail(int x) { for(;s[n-1-len[x]]!=s[n];x=fa[x]); return x; } inline int ins(int c) { s[++n]=c; int p=getfail(las); if(!ne[p][c]) { int u=++siz,q=getfail(fa[p]); len[u]=len[p]+2; fa[u]=ne[q][c]; ne[p][c]=u; } las=ne[p][c]; return las; } void dfs(int u,int pre) { if(pre==-1) h[u]=0; else h[u]=(h[pre]+(len[u]<=0?0:p[len[u]]))%mod; f[u][0]=pre; fo(i,1,18) if(f[u][i-1]!=-1) f[u][i]=f[f[u][i-1]][i-1]; for(auto v:adj[u]) dfs(v,u); } void work() { fo(i,0,siz) if(i!=1) adj[fa[i]].pb(i); fo(u,0,siz) fo(i,0,18) f[u][i]=-1; dfs(1,-1); } inline int jump(int u,int k) { fd(i,18,0) if(f[u][i]!=-1&&len[f[u][i]]>=k) u=f[u][i]; return u; } inline int get(int x,int y) { return jump(pos[y],y-x+1); } inline int solve(int x,int y) { fd(i,18,0) if(f[x][i]!=-1&&f[y][i]!=-1) if((h[x]-h[f[x][i]]+mod)%mod==(h[y]-h[f[y][i]]+mod)%mod) x=f[x][i],y=f[y][i]; if(f[x][0]==-1) return 0; return len[x]>len[y]?1:-1; } } int n; char s[N]; int main() { p[0]=1; ff(i,1,N) p[i]=p[i-1]*base%mod; CASET { n=read(); scanf("%s",s+1); PAM::init(); fo(i,1,n) pos[i]=PAM::ins(s[i]-'a'); PAM::work(); int a,b,c,d,t; CASET { a=read(); b=read(); c=read(); d=read(); if(b-a+1!=d-c+1) { puts((b-a+1>d-c+1)?"cslnb":"sjfnb"); continue; } t=PAM::solve(PAM::get(a,b),PAM::get(c,d)); if(t==0) puts("draw"); else puts((t==1)?"cslnb":"sjfnb"); } } return 0; }
|