https://vjudge.net/problem/SPOJ-DISUBSTR
https://www.luogu.org/problemnew/show/SP694
http://www.spoj.com/problems/DISUBSTR/en/
?????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????-height???
????????????????????????height?????????????????????????????????????????????
??????????????????……???
??????????????????????????????????????????????????????????????????
???????????????????????????
?????????????????????????????????
#include<algorithm> #include<iostream> #include<cstring> #include<cctype> #include<cstdio> #include<vector> #include<queue> #include<cmath> using namespace std; const int N=1010; char s[N]; int n,rk[N],sa[N],height[N],w[N]; inline bool pan(int *x,int i,int j,int k){ int ti=i+k<n?x[i+k]:-1; int tj=j+k<n?x[j+k]:-1; return x[i]==x[j]&&ti==tj; } inline void SA_init(){ int *x=rk,*y=height,r=256; for(int i=0;i<r;i++)w[i]=0; for(int i=0;i<n;i++)w[s[i]]++; for(int i=1;i<r;i++)w[i]+=w[i-1]; for(int i=n-1;i>=0;i--)sa[--w[s[i]]]=i; r=1;x[sa[0]]=0; for(int i=1;i<n;i++) x[sa[i]]=s[sa[i]]==s[sa[i-1]]?r-1:r++; for(int k=1;r<n;k<<=1){ int yn=0; for(int i=n-k;i<n;i++)y[yn++]=i; for(int i=0;i<n;i++) if(sa[i]>=k)y[yn++]=sa[i]-k; for(int i=0;i<r;i++)w[i]=0; for(int i=0;i<n;i++)++w[x[y[i]]]; for(int i=1;i<r;i++)w[i]+=w[i-1]; for(int i=n-1;i>=0;i--)sa[--w[x[y[i]]]]=y[i]; swap(x,y);r=1;x[sa[0]]=0; for(int i=1;i<n;i++) x[sa[i]]=pan(y,sa[i],sa[i-1],k)?r-1:r++; } for(int i=0;i<n;i++)rk[i]=x[i]; } inline void height_init(){ int i,j,k=0; for(i=1;i<=n;i++)rk[sa[i]]=i; for(i=0;i<n;i++){ if(k)k--; else k=0; j=sa[rk[i]-1]; while(s[i+k]==s[j+k])k++; height[rk[i]]=k; } } int main(){ int t; scanf("%d",&t); while(t--){ cin>>s; n=strlen(s); n++; SA_init(); n--; height_init(); int ans=(1+n)*n/2;; for(int i=2;i<=n;i++)ans-=height[i]; printf("%d\n",ans); } return 0; }
+++++++++++++++++++++++++++++++++++++++++++
+???????????????luyouqi233??? ??????????????????????????????????????????+
+???????????????????????????http://www.cnblogs.com/luyouqi233/+
+++++++++++++++++++++++++++++++++++++++++++