Title Description
Given a string . To ensure that each character is a lowercase letter. Ss for each position, the number of the request to the end of the palindromic substring position.
This string is encrypted, except for the first character, other characters need to be decrypted by the answers on a location.
Specific areas, young first The answer is location , first characters read in the code , subsection character real code . All characters before and after encryption are all lowercase letters.
Input Format
A string line represents a string is encrypted.
Output Format
Line, integers. The first integer represents the original string to the first The number of characters in the substring palindrome end.
Palindrome tree template title, but by force, we need to use the front of the palindromic sequence number k
#include<bits/stdc++.h>
using namespace std;
const int MAXNODE = 6e5+50;
const int MOD = 1e9+7;
struct Palindrome{
int nxt[MAXNODE][26],fail[MAXNODE],len[MAXNODE],cnt[MAXNODE];
int sz,last,sn;
char s[MAXNODE];
Palindrome(){
len[0]=0,len[1]=-1;
fail[0]=1,fail[1]=0;
last = sn = 0,sz = 1;
s[0] = '#';//将第一个字符表示成字符串中没出现过的字符
}
int Build(char ch){
s[++sn] = ch;
int root = last;
while(s[sn-len[root]-1]!=ch)
root = fail[root];
if(!nxt[root][ch-'a']){
len[++sz] = len[root] + 2;
int tmp = fail[root];
while(s[sn-len[tmp]-1]!=ch)
tmp = fail[tmp];
fail[sz] = nxt[tmp][ch-'a'];
cnt[sz] = cnt[fail[sz]] + 1;
nxt[root][ch-'a'] = sz;
}
last = nxt[root][ch-'a'];
return cnt[last];
}
}PAM;
char str[MAXNODE];
int main(){
scanf("%s",str);
int len = strlen(str);
for(int i=0,k=0;i<len;i++){
str[i] = (str[i]-97+k)%26+97;
k = PAM.Build(str[i]);
printf("%d ",k);
}
return 0;
}