Evaluation Address: https://cn.vjudge.net/problem/CSU-1632
Description
in the string, all occurrences of at least 2 number of sub-strings of the second
Input
first act an integer T (t<=10) represents the number of use case groups, with each group of use cases occupying a length of 100000 the string
Output
For each set of use cases, output the number of substrings that appear at least two times in the string
Sample Input
3
Aabaab
Aaaaa
AaAaA
Sample Output
5
4
5
Solution
Ans=sum ( max (height (i)-height (i-1), 0) )
#include <cstdio>#include<cstring>using namespacestd;Const intn=1e5+5;intT,n,ans,c[n],sa[n],tsa[n],trank[n],rank[n],h[n];CharS[n];voidDA (intmaxx= the) {memset (c,0,sizeofc);intp; for(intI=1; i<=n;i++) c[rank[i]=s[i]]++; for(intI=2; i<=maxx;i++) c[i]+=c[i-1]; for(inti=n;i;i--) sa[c[rank[i]]--]=i; trank[sa[1]]=p=1; for(intI=2; i<=n;i++){ if(rank[sa[i]]!=rank[sa[i-1]]) p++; Trank[sa[i]]=p; } for(intI=1; i<=n;i++) rank[i]=Trank[i]; for(intk=1;p <n;k<<=1, maxx=p) {P=0; for(inti=n-k+1; i<=n;i++) tsa[++p]=i; for(intI=1; i<=n;i++)if(sa[i]>k) tsa[++p]=sa[i]-K; Memset (c,0,sizeofc); for(intI=1; i<=n;i++) trank[i]=Rank[tsa[i]]; for(intI=1; i<=n;i++) c[trank[i]]++; for(intI=2; i<=maxx;i++) c[i]+=c[i-1]; for(inti=n;i;i--) sa[c[trank[i]]--]=Tsa[i]; trank[sa[1]]=p=1; for(intI=2; i<=n;i++){ if(rank[sa[i]]!=rank[sa[i-1]]|| rank[sa[i]+k]!=rank[sa[i-1]+K]) p++; Trank[sa[i]]=p; } for(intI=1; i<=n;i++) rank[i]=Trank[i]; } for(intI=1, k=0; i<=n;i++){ intj=sa[rank[i]-1]; while(S[i+k]==s[j+k]) k++; H[rank[i]]=k;if(k>0) k--; }}voidGO () {ans=0; for(intI=1; i<=n;i++)if(h[i]>h[i-1]) ans+=h[i]-h[i-1]; printf ("%d\n", ans);}intMain () {scanf ("%d",&T); while(t--) {scanf ("%s", s+1); N=strlen (s+1); DA (); GO (); } return 0;}
CSU-1632 repeated substrings[suffix array to find the number of substrings that occur repeatedly]