比较裸的后缀数组。

/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ //By BLADEVIL
var
s, str :array[..] of char;
n, m, l :longint;
i :longint;
ws, wv :array[..] of longint;
w :array[..,..] of longint;
r, sa :array[..] of longint; procedure da;
var
i, j, p, k1, k2 :longint;
begin
for i:= to m do ws[i]:=;
for i:= to n do
begin
w[i][]:=r[i];
inc(ws[r[i]]);
end;
for i:= to m do inc(ws[i],ws[i-]);
for i:=n downto do
begin
dec(ws[w[i][]]);
sa[ws[w[i][]]]:=i;
end; j:=; p:=;
k1:=; k2:=;
while p<=n do
begin
p:=; i:=n-j+;
while i<=n do
begin
w[p][k2]:=i;
inc(p);
inc(i);
end;
for i:= to n do
if sa[i]>=j then
begin
w[p][k2]:=sa[i]-j;
inc(p);
end; for i:= to n do wv[i]:=w[w[i][k2]][k1];
for i:= to m do ws[i]:=;
for i:= to n do inc(ws[wv[i]]);
for i:= to m do inc(ws[i],ws[i-]);
for i:=n downto do
begin
dec(ws[wv[i]]);
sa[ws[wv[i]]]:=w[i][k2];
end; k1:=k1 xor ;
k2:=k2 xor ;
p:=;
w[sa[]][k1]:=;
for i:= to n do
begin
if (w[sa[i-]][k2]=w[sa[i]][k2]) and (w[sa[i-]+j][k2]=w[sa[i]+j][k2]) then
w[sa[i]][k1]:=p- else
begin
w[sa[i]][k1]:=p;
inc(p);
end;
end;
j:=j<<; m:=p;
end; end; begin
n:=;
while not eoln do
begin
read(str[n]);
inc(n);
end;
l:=n; dec(n);
s:=str;
for i:=n+ to *n+ do s[i]:=str[i-n-];
n:=*n+;
s[n]:=chr();
for i:= to n do
begin
r[i]:=ord(s[i]);
if r[i]>m then m:=r[i];
end;
da;
for i:= to n do
if sa[i]<l then write(s[sa[i]+l-]);
writeln;
end.
05-27 04:49