Description
For a given string of length n, ask what the K-string is.
Input
The first line is a string that consists only of lowercase English letters s
The second behavior of two integers T and k,t to 0 means that the same substring at different locations counts as one. T=1 means that the same substring in different locations counts as multiple. The significance of K title described. Output
The output is only one row, which is a string of numbers, and is a small substring of K. If the number of substrings is less than K, the output-1
Sample InputAABC
0 3Sample OutputAaB
HINT
N<=5*10^5
T<2k<=10^9
Ideas
0 is the same as the problem. The number of occurrences of each substring counts as 1;
As for 1, statistics Val as the number of times the substring appears in different locations, modify it accordingly.
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5 Const intN =5*1e5+Ten;6 7 CharS[n];8 introot,last,sz,ch[n][ -],fa[n],sum[n],val[n],l[n];9 voidAddintx) {Ten intc=s[x]-'a'; One intP=last,np=++sz; last=NP; Al[np]=x+1; val[np]=1; - for(;p &&!ch[p][c];p =fa[p]) ch[p][c]=NP; - if(!p) fa[np]=Root; the Else { - intq=Ch[p][c]; - if(l[p]+1==L[Q]) fa[np]=Q; - Else { + intNq=++sz; l[nq]=l[p]+1; -memcpy (Ch[nq],ch[q],sizeof(Ch[q])); +fa[nq]=Fa[q]; Afa[np]=fa[q]=NQ; at for(;p &&q==ch[p][c];p =fa[p]) ch[p][c]=NQ; - } - } - } - - intN,t,b[n],cnt[n]; in - voidget_sum () { to for(intI=1; i<=sz;i++) cnt[l[i]]++; + for(intI=1; i<=n;i++) cnt[i]+=cnt[i-1]; - for(inti=sz;i>=1; i--) b[cnt[l[i]]--]=i; the for(inti=sz;i;i--) * if(! T) val[b[i]]=1; $ Elseval[fa[b[i]]]+=Val[b[i]];Panax Notoginsengval[1]=0; - for(inti=sz;i;i--) { the intP=b[i]; sum[p]=Val[p]; + for(intj=0;j< -; j + +) Asum[p]+=Sum[ch[p][j]]; the } + } - $ intMain () { $scanf"%s", s); -n=strlen (s); -root=last=++sz; the for(intI=0; i<n;i++) Add (i); -scanf"%d",&T);Wuyi intX,p=root; scanf"%d",&x); the get_sum (); - if(x>sum[1]) {puts ("-1");return 0; } Wu while(x>Val[p]) { - for(intC=0;c< -; C + +)if(Ch[p][c]) { About if(sum[ch[p][c]]>=x) { $Putchar ('a'+c); -X-=VAL[P]; p=Ch[p][c]; - Break; - } A Elsex-=Sum[ch[p][c]]; + } the } - return 0; $}
bzoj3998 [TJOI2015] string theory (SAM)