Skr(马拉车+哈希)

A number is skr, if and only if it's unchanged after being reversed. For example, "12321", "11" and "1" are skr numbers, but "123", "221" are not. FYW has a string of numbers, each substring can present a number, he wants to know the sum of distinct skr number in the string. FYW are not good at math, so he asks you for help.

Input

The only line contains the string of numbers SSS.

It is guaranteed that 1≤S[i]≤91 \le S[i] \le 91≤S[i]≤9, the length of SSS is less than 200000020000002000000.

Output

Print the answer modulo 100000000710000000071000000007.

样例输入1

111111

样例输出1

123456

样例输入2

1121

样例输出2

135
#include<bits/stdc++.h>
using namespace std;

typedef unsigned long long ULL;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)

const int N=2e6+10;
const int mod=1e9+7;


char s[N];

ULL base[N*2],has[N*2];//auto
LL base10[N*2],sum[N*2];


const ULL P=1000007;
int fir[N<<1],nxt[N<<1],cnt=0;
ULL has_link[N<<1];
int HAS(ULL x){
    ULL t=x%P;
    for(int i=fir[t];i;i=nxt[i]){
        if(has_link[i]==x)return 1;
    }
    nxt[++cnt]=fir[t];
    fir[t]=cnt;
    has_link[cnt]=x;
    return 0;
}

LL solve(int l,int r){
    ULL v=has[r]-has[l-1]*base[r-l+1];
    if(HAS(v))return 0;
    LL res=(sum[r]-sum[l-1]*base10[(r-l+2)/2]%mod+mod)%mod;
    return res;
}

char Ma[N*2];
int Mp[N*2];//record radius
void Manacher(char s[],int len){
    int l=0;
    Ma[l++]='$';//head
    Ma[l++]='#';
    rep(i,0,len){
        Ma[l++]=s[i];
        Ma[l++]='#';
    }
    Ma[l]=0;//tail

    base[0]=base10[0]=1;
    sum[0]=has[0]=0;
    rep(i,1,l+1){
        base[i]=base[i-1]*P,has[i]=has[i-1]*P+Ma[i];

        base10[i]=base10[i-1]*10%mod;
        if(Ma[i]>='0'&&Ma[i]<='9') sum[i]=(sum[i-1]*10+Ma[i]-'0')%mod;
        else sum[i]=sum[i-1];
    }

    int mx=0,id=0;//record max_pos
    LL ans=0;
    rep(i,1,l){
        if(Ma[i]!='#')ans=(ans+solve(i,i))%mod;
        Mp[i]=mx>i?min(Mp[2*id-i],mx-i):1;
        while(Ma[i+Mp[i]]==Ma[i-Mp[i]]){
            if(Ma[i+Mp[i]]!='#')ans=(ans+solve(i-Mp[i],i+Mp[i]))%mod;
            ++Mp[i];//exceed mx
        }
        if(i+Mp[i]>mx){
            mx=i+Mp[i];
            id=i;
        }
    }
    printf("%lld\n",ans);
}

int main(){
    scanf("%s",s);
    int len=strlen(s);
    Manacher(s,len);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值