Bzoj 2754: [SCOI2012] The name suffix array on the Meow planet

Source: Internet
Author: User
Tags printf

I heard that this problem suffix array violence can pass, then I did not write the ghost of the algorithm, all the strings are glued together, processed out of the suffix array and then violently swept again.

#include <cstdio> #include <cstdlib> #include <cmath> #include <ctime> #include <cstring> #include <string> #include <iostream> #include <iomanip> #include <algorithm> using namespace
Std
int sa[500000];
int rank[500000];
int s[500000];
int temp[500000];
int x[500000];
int y[500000];
int height[500000];
int sum[500000];
int num[500000];
int len=0;
    void Get_rank () {for (int i=1;i<=len;i++) sum[s[i]]++;
    for (int i=1;i<=10001;i++) sum[i]+=sum[i-1];
    for (int i=len;i>=1;i--) temp[sum[s[i]]--]=i;
    int tot=0;
        for (int i=1;i<=len;i++) {if (S[temp[i]]!=s[temp[i-1] | | | i==1) tot++;
    Rank[temp[i]]=tot;
    }} void Ji_sort (int key[],int order[]) {for (int i=0;i<=len;i++) sum[i]=0;
    for (int i=1;i<=len;i++) sum[key[i]]++;
    for (int i=1;i<=len;i++) sum[i]+=sum[i-1];
    for (int i=len;i>=1;i--) temp[sum[key[order[i]]]--]=order[i];
for (int i=1;i<=len;i++) order[i]=temp[i]; } void GET_hou () {Get_rank ();
            for (int. j=1;j<=len;j<<=1) {for (int i=1;i<=len;i++) {x[i]=rank[i]; Y[i]=i+j>len?
            0:RANK[I+J];
        Sa[i]=i;
        } ji_sort (Y,SA);
        Ji_sort (X,SA);
        int tot=0;
                for (int i=1;i<=len;i++) {if (X[sa[i]]!=x[sa[i-1]] | | y[sa[i]]!=y[sa[i-1] | | | i==1)
            tot++;

        Rank[sa[i]]=tot;
        }}} void Get_height () {for (int i=1;i<=len;i++) {if (rank[i]==1) continue;
        int K=max (0,HEIGHT[RANK[I-1]]-1);
        while (S[i+k]==s[sa[rank[i]-1]+k]) k++;
    Height[rank[i]]=k;
}} int qi[100000];
int leng[100000];
int ci[100000];
BOOL pd[100000];
int time_clock[100000];
    int main () {int n,m;
    scanf ("%d%d", &n,&m);
    len=0;
        for (int i=1;i<=n;i++) {int t;
        scanf ("%d", &t); for (int j=1;j<=t;j++) {scanf ("%d", &s[++len]);
        Num[len]=i;
        } s[++len]=10001;
        scanf ("%d", &t);
            for (int j=1;j<=t;j++) {scanf ("%d", &s[++len]);
        Num[len]=i;
    } s[++len]=10001;
        } for (int i=1;i<=m;i++) {scanf ("%d", &leng[i]);
        qi[i]=len+1;
        for (int j=1;j<=leng[i];j++) scanf ("%d", &s[++len]);
    s[++len]=10001;
    } Get_hou ();
    Get_height ();
        for (int i=1;i<=m;i++) {int t=rank[qi[i]];
        int ans=0;
            while (Height[t]>=leng[i]) {t--;
            int mid=num[sa[t]];
                    if (mid) {if (time_clock[mid]!=i) {time_clock[mid]=i;
                Pd[mid]=false;
                    } if (!pd[mid]) {ci[mid]++;
                    Pd[mid]=true;
                ans++;
     }
            }
        }   while (Height[t+1]>=leng[i]) {t++;
            int mid=num[sa[t]];
                    if (mid) {if (time_clock[mid]!=i) {time_clock[mid]=i;
                Pd[mid]=false;
                    } if (!pd[mid]) {ci[mid]++;
                    Pd[mid]=true;
                ans++;
    }}} printf ("%d\n", ans);
    } for (int i=1;i<n;i++) printf ("%d", ci[i]);
    printf ("%d", ci[n]);
return 0; }

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.