• bzoj1031 [JSOI2007]字符加密Cipher


    老张让弄专题,分到了数据结构,于是愉快地打了一周数据结构。

    觉得还是要水一水bzoj,然后随便打开了一道,竟然是后缀数组模板。。

    这周没写博客呀。。现在去补。。

    //Achen
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<vector>
    #include<queue>
    #include<ctime>
    #include<cmath>
    const int N=200007; 
    typedef long long LL;
    using namespace std;
    int sa[N],len,n,m=257,sz;
    char s[N],as[N];
    
    template<typename T> void read(T &x) {
        char ch=getchar(); x=0; T f=1;
        while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
        if(ch=='-') f=-1,ch=getchar();
        for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    }
    
    int cmp(int *y,int k,int a,int b) {
        int o1=a+k>=n?-1:y[a+k];
        int o2=b+k>=n?-1:y[b+k];
        return (o1==o2)&&(y[a]==y[b]);
    } 
    
    void makesa() {
        static int i,t1[N],t2[N],c[N],*x=t1,*y=t2;
        for(i=0;i<m;i++) c[i]=0;
        for(i=0;i<n;i++) c[x[i]=s[i]]++;
        for(i=1;i<m;i++) c[i]+=c[i-1];
        for(i=n-1;i>=0;i--) sa[--c[x[i]]]=i;
        for(int k=1;k<n;k<<=1) {
            int p=0;
            for(i=n-k;i<n;i++) y[p++]=i;
            for(i=0;i<n;i++) if(sa[i]>=k) y[p++]=sa[i]-k;
            for(i=0;i<m;i++) c[i]=0;
            for(i=0;i<n;i++) c[x[y[i]]]++;
            for(i=1;i<m;i++) c[i]+=c[i-1];
            for(i=n-1;i>=0;i--) sa[--c[x[y[i]]]]=y[i];
            swap(x,y); p=1; x[sa[0]]=0;
            for(i=1;i<n;i++) 
            x[sa[i]]=cmp(y,k,sa[i],sa[i-1])?p-1:p++;
            if(p>=n) break;
            m=p;
        }
    }
    
    int main() {
    #ifdef DEBUG
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
        scanf("%s",s);
        len=strlen(s); n=len;
        for(int i=0;i<len;i++) s[n++]=s[i];
        makesa();
        for(int i=0;i<n;i++) {
            if(sa[i]<len) 
            as[sz++]=s[sa[i]+len-1];
        }
        puts(as);
        return 0;
    }
    View Code
  • 相关阅读:
    致我的2018 你好2019
    第十四分块(前体)(二次离线莫队)
    [Ynoi2019模拟赛]Yuno loves sqrt technology II(二次离线莫队)
    [Ynoi2015]此时此刻的光辉(莫队)
    python+selenium+Firefox+pycharm版本匹配
    IntelliJ IDEA 配置Maven
    Jmeter如何监控服务器性能
    fiddler工具
    关于Python安装官方whl包和tar.gz包的方法详解
    浅析Web Services
  • 原文地址:https://www.cnblogs.com/Achenchen/p/8021427.html
Copyright © 2020-2023  润新知