Number of substrings not duplicated
With all the minus the height is good to launch ...
#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN =1010, INF =0x7fffffff;CharA[MAXN];intS[MAXN];intSA[MAXN], T[MAXN], T2[MAXN], C[MAXN], N;intRAN[MAXN], HEIGHT[MAXN];voidGet_sa (intm) { intI, *x = t, *y =T2; for(i =0; I < m; i++) C[i] =0; for(i =0; I < n; i++) C[x[i] = s[i]]++; for(i =1; I < m; i++) C[i] + = c[i-1]; for(i = n1; I >=0; i--) Sa[--c[x[i]] =i; for(intK =1; K <= N; K <<=1) { intp =0; for(i = n-k; i < n; i++) y[p++] =i; for(i =0; I < n; i++)if(Sa[i] >= k) y[p++] = Sa[i]-K; for(i =0; I < m; i++) C[i] =0; for(i =0; I < n; i++) c[x[y[i]]]++; for(i =0; i< m; i++) C[i] + = c[i-1]; for(i = n1; I >=0; i--) sa[--c[x[y[i] []] =Y[i]; Swap (x, y); P=1; x[sa[0]] =0; for(i =1; I < n; i++) X[sa[i]]= y[sa[i-1] [= Y[sa[i]] && y[sa[i-1]+k] = = Y[sa[i]+k]? P1: p++; if(P >= N) Break; M=p; } intK =0; for(i =0; I < n; i++) Ran[sa[i] =i; for(i =0; I < n; i++) { if(k) k--; intj = sa[ran[i]-1]; while(S[i+k] = = S[j+k]) k++; Height[ran[i]]=K; }}intMain () {intT; RD (T); while(t--) {RS (a); N=strlen (a); Rep (I,0, N) s[i]=A[i]; intsum = N (n+1)/2; S[n++] =0; Get_sa ( the); Rep (I,1, N) sum-=Height[i]; cout<< sum <<Endl; } return 0;}
Distinct substrings spoj-disubstr (suffix array water problem)