bzoj1031: [JSOI2007] character encryption cipher suffix array

Source: Internet
Author: User

Because it is a ring, it can be reproduced in the back again.

#include <bits/stdc++.h>using namespace Std;int n,sa[202000],rank[202000],temp[202000],p[202000],cnt[202000] , Height[202000],str[202000];char s[202000];bool epu (int x,int y,int l) {return rank[x]==rank[y]&&rank[x+l]== RANK[Y+L];}    void doubling () {str[n]=rank[n]=-1;    for (int i=0;i<n;i++) str[i]=s[i];    for (int i=0;i<n;i++) sa[i]=i,rank[i]=str[i];        for (int. L=0,pos=0,sig=255,i;pos<n-1;sig=pos) {for (i=n-l,pos=0;i<n;i++) p[pos++]=i;        for (i=0;i<n;i++) if (sa[i]>=l) p[pos++]=sa[i]-l;        memset (cnt,0,sizeof (CNT));        for (i=0;i<n;i++) cnt[rank[p[i]]]++;        for (i=1;i<=sig;i++) cnt[i]+=cnt[i-1];        for (i=n-1;i>=0;i--) sa[--cnt[rank[p[i]]]]=p[i];            for (temp[sa[0]]=pos=0,i=1;i<n;i++) {if (!epu (sa[i],sa[i-1],l)) pos++;        Temp[sa[i]]=pos;        } for (i=0;i<n;i++) rank[i]=temp[i];    if (!l) L=1;else l<<=1;    }}void Pre () {int i,j,k; for (i=0,k=0;i<n;i++) {if (k) k-;        if (rank[i]==0) continue;        For (J=sa[rank[i]-1];str[j+k]==str[i+k];) k++;    Height[rank[i]]=k;    }}int Main () {//freopen ("xf.in", "R", stdin);    scanf ("%s", s);    N=strlen (s);    for (int i=0;i<n;i++) s[n+i]=s[i];    n*=2;    Doubling ();    Pre ();    for (int i=0;i<n;i++) if (SA[I]&LT;N/2) printf ("%c", s[sa[i]+n/2-1]);    printf ("\ n"); return 0;}

  

bzoj1031: [JSOI2007] 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.