Because I have not learned the standard SA writing, has been written in accordance with their own blind yy n*log^2 to do
But it's been stuck a few times.
The practice is to record rk[] and rk2[] as the first and second keywords for sort//to do so the first keyword ordered cardinal sort constant huge
Luogu Template n*log^2 70 min
Change to cardinality (great constant edition) sort 9s AC
So I yy out an unknown complexity of the algorithm. Complexity is probably n*log*log (N/log)
Measured 5s AC
Algorithm record Sa[i] indicates where the position of rank i is
There is no difference between an SA sequence and an ordinary base row.
Next we consider
Each rk[sa[i]] is ordered, and Rk2[sa[i]] is unordered
So according to the RK segment, each time only the RK equal to a section of the order, so that the length of each order can be considered n/log.
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <ctime > #include <cstdlib> #include <algorithm> #include <queue> #define for (i,j,k) for (int i=j;i<=k;+
+i) #define DOW (I,J,K) for (int i=k;i>=j;--i) #define LL Long long #define INF 1e9 using namespace std;
inline int read () {int T=0,f=1;char c=getchar ();
while (!isdigit (c)) {if (c== '-') F=-1;c=getchar ();}
while (IsDigit (c)) t=t*10+c-' 0 ', C=getchar ();
return t*f;
} inline void write (int x) {if (x>=10) write (X/10);p Utchar (x%10+ ' 0 ');} inline void Writeln (int x) {write (x);p UTS ("");
inline void write_p (int x) {write (x);p Utchar (");} int sa[2000001],n,rk[2000001],rk2[2000001],tmp[2000001];
Char s[2000001]; inline BOOL cmp (int x,int y) {return rk[x]==rk[y]?rk2[x]<rk2[y]:rk[x]<rk[y];} inline void Resort (int p[]) {i
NT Las=1;
for (I,2,n) if (rk[p[i]]!=rk[p[i-1])//processing las~i-1 {sort (p+las,p+i,cmp);
Las=i;} sort (p+las,p+n+1,cmp);
} int main () {scanf ("%s", s+1); N=strlen (s+1);
for (i,1,n) rk[i]=s[i],sa[i]=i;
Sort (sa+1,sa+n+1,cmp);
for (int. len=1;len<=n;len*=2) {for (i,1,n) rk2[i]=i+len<=n?rk[i+len]:0;
Resort (SA);
int tot=1;
Tmp[sa[1]]=1;
for (I,2,n) if (Rk[sa[i]]==rk[sa[i-1]]&&rk2[sa[i]]==rk2[sa[i-1]]) Tmp[sa[i]]=tot;else Tmp[sa[i]]=++tot;
Swap (RK,TMP);
} for (I,1,n) write_p (Sa[i]); }