zoukankan      html  css  js  c++  java
  • 【NOIP2017提高A组冲刺11.8】好文章

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    
    typedef long long ll;
    
    struct HH{
        ll mod,base,d;
        ll sta;
        void update(int x){
            sta+=x;sta*=base;sta%=mod;
        }
        void del(int x){
            sta-=(x*d);
            while(sta<0) sta+=mod;
        }
    }h1,h2;
    
    const int MAXN=2000005;
    
    ll qpow(ll x,int y,ll mod){
        ll ret=1;
        while(y){
            if(y&1){ret*=x;ret%=mod;}
            x*=x;x%=mod;
            y>>=1;
        }
        return ret;
    }
    
    struct Node{
        ll x,y;
        Node(ll u=0,ll v=0){x=u;y=v;}
        bool operator <(const Node &rhs) const {
            return x==rhs.x?y<rhs.y:x<rhs.x;
        }
    }node[MAXN];
    int tot;
    
    int n,m;
    char s[MAXN];
    int ans=1;
    
    signed main(){
    //    freopen("article.in","r",stdin);
    //    freopen("article.out","w",stdout);
        scanf("%d%d",&n,&m);
        h1.base=27;h2.base=27;
        h1.mod=19260817;
        h2.mod=19491001;
        h1.d=qpow(h1.base,m,h1.mod);
        h2.d=qpow(h2.base,m,h2.mod);
        scanf("%s",s+1);
        for(int i=1;i<=m;i++){
            h1.update(s[i]-'a');
            h2.update(s[i]-'a');
        }
        node[++tot]=(Node(h1.sta,h2.sta));
        for(int i=m+1;i<=n;i++){
            h1.del(s[i-m]-'a');
            h2.del(s[i-m]-'a');
            h1.update(s[i]-'a');
            h2.update(s[i]-'a');
            node[++tot]=(Node(h1.sta,h2.sta));
        }
        sort(node+1,node+1+tot);
        for(int i=2;i<=tot;i++){
            if(node[i].x!=node[i-1].x||node[i].y!=node[i-1].y) ans++;
        }
        cout<<ans;
        return 0;
    }
    未经许可,禁止搬运。
  • 相关阅读:
    Linux 下杀毒可用工具 clamav
    Docker 添加环境系统文件配置
    Docker 空间大小设置
    Docker 扩容 容器空间大小
    bzoj 1088 DP
    bzoj 1096 斜率优化DP
    spoj p104 Matrix-Tree定理
    bzoj 1016 深搜
    WC后记
    bzoj 1301 后缀数组
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9502780.html
Copyright © 2011-2022 走看看