Exemplo n.º 1
0
int main()
{
	freopen("1.in","r",stdin);
	freopen("3.out","w",stdout);
    int totcas;
    scanf("%d",&totcas);
    //totcas = 20;
    hash.init();
    for (int cas = 1; cas <= totcas; cas++)
    {
        //for (int i = 0;i < maxn-10;i++)
        //    s[i] = rand()%1+'a';
        //s[maxn-10] = 0;
        scanf("%s",s);
        len = strlen(s);
        Manacher(s,len);

        sum[0] = s[0];
        mutpower[0] = 1;
        for (int i = 1; i < len; i++)
        {
            mutpower[i] = (long long)mutpower[i-1]*muts%mods;
            sum[i] = (sum[i-1]+(long long)s[i]*mutpower[i])%mods;
        }
        int res = 0;
        int tmp;

        //for (int i = 0;i < len*2+2;i++)
        //    printf("%2d ",Mp[i]);
        //printf("\n");

		if (cas == 10)
		{
			for (int i = 10000;i < len;i++)
				for (int j = i-100;j <= i;j++)
					printf("%d\n",gethashcode(j,i));
		}
        hash.clear();
        //odd
        for (int i = 0; i < len; i++)
            if (Mp[i*2+2]%2 == 0)
            {
                int pl = Mp[i*2+2]/2;
                for (int j = i-pl+1; j <= i; j++)
                {
                    tmp = gethashcode(j,i);
                    if (hash.fint(tmp) != -1)    break;
                    hash.insert(tmp);
                }
            }
        res += hash.N;

        hash.clear();
        //even
        for (int i = 0; i < len; i++)
            if (Mp[i*2+3] > 1)
            {
                int pl = Mp[i*2+3]/2;
                for (int j = i-pl+1; j <= i; j++)
                {
                    tmp = gethashcode(j,i);
                    if (hash.fint(tmp) != -1)    break;
                    hash.insert(tmp);
                }
            }
        res += hash.N;

        printf("Case #%d: %d\n",cas,res);
    }
    return 0;
}