The value of a string s is equal to the number of different letters which appear in this string. Your task is to calculate the total value of all the palindrome substring. Input The input consists of a single string |s|(1≤∣s∣≤3×10^5 ). The string s only contains lowercase letters. Output Output an integer that denotes the answer. 样例输入 abac 样例输出 6 样例解释 abac has palindrome substrings a,b,a,c,abaa,b,a,c,aba,ans the total value is equal to 1+1+1+1+2=6。
【题解】
Manacher,先预处理一波,然后找出每一个位置的26个字母下一个位置,存在一个vector里面,然后最后找的时候就是差值 × 对应的个数。
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=3e5+100; 5 char S[N],T[N<<1]; 6 int Len[N*2]; 7 int nxt[N][27]; 8 vector<int>V[N]; 9 void Manacher(char *s){ 10 int L=strlen(s); 11 int po = 0 , mx=0 ; 12 13 for(int i=1;i<=L*2;i++){ 14 T[i] = i&1? '#' : s[i/2-1] ; 15 } 16 17 T[0] = '@'; 18 T[2*L+1] = '#'; 19 T[2*L+2] = '