Just started to ask the height of the array of the place is wrong, it seems that the understanding is not thorough
All substrings minus duplicate substrings
First on the draft paper to think clearly before you start, do not just have a general idea, or error prone #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define N 10005int N;char s[n];int r[n],sa[n],height[n],rank[n],wa[n],wb[n],wv[n],ws[n]; int cmp (int *r,int a,int b,int l) {return r[a]==r[b]&&r[a+l]==r[b+l];} void da (int *r,int *sa,int n,int m) {int i,j,p,*x=wa,*y=wb;for (i=0;i<m;i++) ws[i]=0;for (i=0;i<n;i++) ws[x[i]=r[i] ]++;for (i=1;i<m;i++) ws[i]+=ws[i-1];for (i=n-1;i>=0;i--) sa[--ws[x[i]]]=i;for (j=1,p=1;p<n;m=p,j<<= 1) {for (i=n-j,p=0;i<n;i++) y[p++]=i;for (i=0;i<n;i++) if (sa[i]>=j) y[p++]=sa[i]-j;for (i=0;i<n;i++) wv[i] =x[y[i]];for (i=0;i<m;i++) ws[i]=0;for (i=0;i<n;i++) ws[wv[i]]++;for (i=1;i<m;i++) ws[i]+=ws[i-1];for (i=n-1 ; i>=0;i--) Sa[--ws[wv[i]]]=y[i];swap (x, y), for (i=1,p=1,x[sa[0]]=0;i<n;i++) x[sa[i]]=cmp (y,sa[i-1],sa[i],j)? p-1:p++;}} void calheight (int *r,int *sa,int n) {int i,j,k=0;for (i=1;i<=n;i++) rank[sa[i]]=i;for (i=0;i<n;height[rank[i++]] =k) for (k1//for ("%d", Height[i]) (k--:0,j=sa[rank[i]-1];r[i+k]==r[j+k];k++)///respectively, and their previous one (i=1;i<=n;i++) printf;} int main () {#ifndef online_judgefreopen ("In.txt", "R", stdin), #endifint t,p,q;int cas=1;scanf ("%d", &t); while (t--) {scanf ("%s", s); int N=strlen (s); scanf ("%d%d", &p,&q); int i;for (i=0;i<n;i++) R[i]=s[i];r[n]=0;da (r,sa,n+ 1,129); Calheight (r,sa,n); int ans= (2*n-p-q+2) * (q-p+1)/2;//all substrings of p-q for (i=1;i<=n;i++) {if (height[i]>=p& &HEIGHT[I]<=Q) Ans-=height[i]-p+1;else if (height[i]>q) ans-=q-p+1;} printf ("Case%d:%d\n", Cas++,ans);}}
Lightoj 1314 Names for babies