Palindromes and Super Abilities 2
题目链接:
http://acm.hust.edu.cn/vjudge/contest/126823#problem/E
Description
Dima adds letters s 1, …, s n one by one to the end of a word. After each letter, he asks Misha to tell him how many new palindrome substrings appeared when he added that letter. Two substrings are considered distinct if they are different as strings. Which n numbers will be said by Misha if it is known that he is never wrong?Input
The input contains a string s 1 … s n consisting of letters ‘a’ and ‘b’ (1 ≤ n ≤ 5 000 000).Output
Print n numbers without spaces: i-th number must be the number of palindrome substrings of the prefix s 1 … s i minus the number of palindrome substrings of the prefix s 1 … s i−1. The first number in the output should be one.Sample Input
input output abbbba 111111Notes
We guarantee that jury has C++ solution which fits Time Limit at least two times. We do not guarantee that solution on other languages exists (even Java).##题意: 给出n个字符,要求依次输出填上第i个字符后不同的回文子串的个数增加了多少.
##题解: 可以推导出每次加一个字符,不同回文子串最多增加1个. 后面就没有然后了....
神奇的回文自动机. 先抄个板,后面学习. 这个题也是蛮严格的,卡内存+卡时间+卡输出.(只能用puts)
##代码: ``` cpp #include