• 回文串


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int m1=299993;
    const int m2=1e9+7;
    const int K=13331;
    const int N=600000+10;
    char b[N];
    char a[N];
    int p[N];
    struct point{
        int num,ha;//mod 1e9+7
        int len;
    }poi[N];
    int n,ans;
    ///////////////////////////////
    int nxt[N],pre[N];
    int tot;
    ll h1[N],h2[N];
    ll jin1[N],jin2[N];
    ll H(int st,int ed,int ce){
        ll ret;
        if(ce==1){
            ret=(h1[ed]+m1-h1[st-1]*jin1[ed-st+1])%m1;
        }
        else{
            ret=(h2[ed]+m2-h2[st-1]*jin2[ed-st+1])%m2;
        }
        return ret;
    }
    void insert(ll xi1,ll xi2){
            
    }
    bool check(){
            
    }
    void work(int st,int ed){
        ll ha1=H(st,ed,1);
        ll ha2=H(st,ed,2);
        if(!check(ha1)){
            insert(ha1,ha2);
            if(st!=ed){
            
            }//add edges
        }
        else{
            
        }//++num
    }
    //////////////////////////hash
    void manacher(){
        int id=1,mx=0;
        p[1]=1;
        for(int i=2;i<=n;i++){
            p[i]=min(mx-i,2*id-i);
            if(p[i]<0) p[i]=0;
            int j=i-p[i],k=i+p[i];
            while(j>0&&k<n&&a[k]==a[j]){
                p[i]++;
                if(i+p[i]-1>mx){
                    id=i;
                    mx=i+p[i]-1;
                    work(i-p[i]+1,i+p[i]-1);
                }
                j--,k++;
            }
        }
    }
    ///////////////////////////manacher
    struct node{
        int nxt,to;
    }bian[2*N];
    int hd[N],cnt;
    int du[N];
    void add(int x,int y){
        bian[++cnt].nxt=hd[x];
        bian[cnt].to=y;
        hd[x]=cnt;
        du[y]++;
    }
    int q[N];
    int 
    void topo(){
    }
    //////////////////////////topu
    int main()
    {
        scanf("%s",b+1);
        int m=strlen(b+1);
        for(int i=1;i<=m;i++) a[++n]='#',a[++n]=b[i];
        a[++n]='#';
        jin1[0]=1;jin2[0]=1;
        for(int i=1;i<=n;i++) jin1[i]=(jin1[i-1]*K)%m1,jin2[i]=(jin2[i-1]*K)%m2;
        for(int i=1;i<=n;i++) h1[i]=(h1[i-1]*K+a[i])%m1,h2[i]=(h2[i-1]*K+a[i])%m2;
        
        manacher();
    }
  • 相关阅读:
    HDU 1166 敌兵布阵
    HDU 1397 Goldbach's Conjecture
    VC 界面库皮肤库
    入门基础VC网络编程入门
    入门基础VC网络编程入门(2)
    线程 消息循环
    BMP文件的读取
    Microsoft SQL Server 2008 Enterprise Edition 简体中文企业版
    成功采用设计模式的步骤
    vs2010调试
  • 原文地址:https://www.cnblogs.com/Miracevin/p/9175296.html
Copyright © 2020-2023  润新知