Ideas:
First question
Built suffix array after prefix and pitch n-sa[i]-ht[i]+1 two points
Second question
Two-point judgment is the number of repetitions
How to judge, find it, sweep ht down, sum+= it with K.
Attention is equal to plus one kind of various pits dad details
Die..
//by Siriusren#include <bits/stdc++.h>using namespacestd;Const intn=1000050;intn,cnta[n],cntb[n],a[n],b[n],rk[n],sa[n],tsa[n],ht[n],t,k;Long LongSum[n],sum1[n];CharS[n];voidSA () { for(intI=1; i<=n;i++) cnta[s[i]]++; for(intI=1; i<= the; i++) cnta[i]+=cnta[i-1]; for(inti=n;i;i--) sa[cnta[s[i]]--]=i; rk[sa[1]]=1; for(intI=2; i<=n;i++) rk[sa[i]]=rk[sa[i-1]]+ (s[sa[i]]!=s[sa[i-1]]); for(intL=1; rk[sa[n]]<n;l<<=1) {memset (CntA,0,sizeof(CntA)); memset (CNTB,0,sizeof(CNTB)); for(intI=1; i<=n;i++) cnta[a[i]=rk[i]]++,cntb[b[i]= (I+l<=n?rk[i+l]:0)]++; for(intI=1; i<=n;i++) cnta[i]+=cnta[i-1],cntb[i]+=cntb[i-1]; for(inti=n;i;i--) tsa[cntb[b[i]]--]=i; for(inti=n;i;i--) sa[cnta[a[tsa[i]]]--]=Tsa[i]; rk[sa[1]]=1; for(intI=2; i<=n;i++) rk[sa[i]]=rk[sa[i-1]]+ (a[sa[i]]!=a[sa[i-1]]|| b[sa[i]]!=b[sa[i-1]]); } for(intI=1, j=0; i<=n;i++) {J=j?j-1:0; while(s[i+j]==s[sa[rk[i]-1]+J]) J + +; Ht[rk[i]]=J; }}voidPrintintLintR) { for(inti=l;i<=r;i++) Putchar (S[i]);}BOOLCheckintp) { inttempans=1, l=1, r=N; while(l<=R) { intMid= (l+r) >>1; if(sum[mid]>=p) r=mid-1; ElseTempans=mid+1, l=mid+1; } inthi=p-sum[tempans-1]+ht[tempans],tot=hi+sum1[tempans-1]; if(tot>=k)return 1; for(inti=tempans+1; i<=n;i++) {Hi=min (hi,ht[i]); if(!hi) Break; Tot+=Hi; if(tot>=k)return 1; }return 0;}voidsolve () { for(intI=1, t;i<=n;i++,k-=t) {T=n-sa[i]-ht[i]+1; if(k<=t) {Print (sa[i],sa[i]+k-1+ht[i]);return;} }puts ("-1");} Signed Main () {scanf ("%s%d%d", s+1, &t,&k), N=strlen (s+1), SA (); if(!T) solve (); Else{ for(intI=1; i<=n;i++) sum[i]=sum[i-1]+n-ht[i]-sa[i]+1, sum1[i]=sum1[i-1]+n-sa[i]+1; if(sum1[n]<k) {Puts ("-1");return 0;} intL=1, r=k+1, ans; while(l<=R) { intMid= (l+r) >>1; if(Check (mid)) ans=mid,r=mid-1; ElseL=mid+1; }k=Ans;solve (); }}
Bzoj 3998 suffix array