hash

typedef unsigned long long ull;
ull xp[maxn],hash1[maxn];

void init()
{
    xp[0]=1;
    for (int i=1; i<=maxn; i++)
    {
        xp[i]=xp[i-1]*175;
    }
}

ull get_hash(int i,int l) //以i开始长度为l的字串
{
    return hash1[i]-hash1[i+l]*xp[l];
}

scanf("%s",str);
int len=strlen(str);
for (int i=len-1; i>=0; i--)
{
    hash1[i]=hash1[i+1]*175+str[i]-'a'+1;
}

  

posted @ 2019-08-15 10:36  Snow_in_winer  阅读(144)  评论(0编辑  收藏  举报