"BZOJ1031" character encryption cipher (suffix array)

Source: Internet
Author: User

Test instructions: A string with a length of 2n (copied and pasted) is sorted from small to large, and the last letter of each of them is printed sequentially.

n<=100000

Idea: Bare SA, template really hard back

P Party has to write C + + style

1 varCh:Array[0..300000] ofChar;2A,X,Y,WC,WD,SA:Array[0..300000] ofLongint;3 N,i,m:longint;4 Tmp:char;5  6 functionCMP (A,b,l:longint): boolean;7 begin8Exit ((Y[a]=y[b]) and(y[a+l]=y[b+l]));9 End;Ten   One procedureSwapvarx,y:longint); A varT:longint; - begin -T:=x; X:=y; y:=T; the End; -   - procedureGetsa; - varI,j,p:longint; + begin -   fori:=0  toN-1  Do +  begin Ax[i]:=A[i]; at Inc (Wc[a[i]); -  End; -   fori:=1  toM Dowc[i]:=wc[i-1]+Wc[i]; -   fori:=n-1 Downto 0  Do -  begin - Dec (wc[x[i]]); insa[wc[x[i]]]:=i; -  End; to   +j:=1; p:=1; -   whileP<n Do the  begin *p:=0; $    forI:=n-j toN-1  DoPanax Notoginseng   begin -y[p]:=I; Inc (P); the   End; +    fori:=0  toN-1  Do A    ifSa[i]>=j Then beginY[p]:=sa[i]-j; Inc (P);End; the// fori:=0  toN-1  DoWriteln (Y[i]); +    fori:=0  toN-1  Dowd[i]:=X[y[i]]; -    fori:=0  toM Dowc[i]:=0; $    fori:=0  toN-1  DoInc (Wc[wd[i]); $    fori:=1  toM Dowc[i]:=wc[i-1]+Wc[i]; -    fori:=n-1 Downto 0  Do -   begin the Dec (wc[wd[i]]); -sa[wc[wd[i]]]:=Y[i];Wuyi   End; the   -    fori:=0  toN Doswap (x[i],y[i]); Wu   -p:=1; x[sa[0]]:=0; About    fori:=1  toN-1  Do $   begin -    ifCMP (sa[i-1],SA[I],J) Thenx[sa[i]]:=p-1 -     Else beginX[sa[i]]:=p; Inc (P);End; -   End; A   +j:=j*2; them:=p; -  End; $ End; the   the   the begin theAssign (input,'bzoj1031r.in'); Reset (input); -Assign (output,'Bzoj1031r.out'); Rewrite (output); in   while  notEoln Do the  begin the read (TMP); About Inc (n); thech[n]:=tmp; the  End; the   fori:=1  toN Doa[i-1]:=Ord (Ch[i]); +   forI:=n toN2-1  Doa[i]:=a[i-n]; -n:=n*2+1; m:= -; the Getsa;Bayi   fori:=1  toN-1  Do the   ifsa[i]< (n>>1) Then the   begin -    ifsa[i]=0  ThenWrite (Chr (a[n-2])) -     ElseWrite (Chr (a[sa[i]-1])); the   End; the close (input); the close (output); the   -   the End.

"BZOJ1031" character encryption cipher (suffix array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.