var n:longint; nt:array[0..200008,0..26] of longint; size,l,fa:array[0..200008] of longint; s:array[0..200008] of char; cnt,last:longint; procedure init; begin fa[0]:=1; fa[1]:=1; l[1]:=-1; last:=0; cnt:=1; end; procedure add(c,n:longint); var p,now,k:longint; begin p:=last; while s[n-l[p]-1]<>s[n] do p:=fa[p]; if nt[p][c]=0 then begin inc(cnt); now:=cnt; k:=fa[p]; l[now]:=l[p]+2; while s[n-l[k]-1]<>s[n] do k:=fa[k]; fa[now]:=nt[k][c]; nt[p][c]:=now; end; last:=nt[p][c]; inc(size[last]); end; procedure solve; var i:longint; begin for i:=cnt downto 1 do begin inc(size[fa[i]],size[i]); writeln(size[i],‘ ‘,l[i]); end; end; begin n:=0; init; while not eoln do begin inc(n); read(s[n]); add(ord(s[n])-96,n); end; solve; end.
时间: 2024-11-08 10:51:17