Ural2040:Palindromes and Super Abilities(离线&manecher算法)
2018-04-19 22:17
453 查看
Dima adds letters s1, …, sn 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?
Problem Author: Mikhail Rubinchik (prepared by Kirill Borozdin)
Problem Source: Ural FU Dandelion contest. Petrozavodsk training camp. Summer 2014
题意:问从左向右,每次加入一个字符,新增加了多少个回文串(之前未出现过)。
思路:先用马拉车算法,得到每一个回文串的结束位置,以及对应的hash值(vector保存)。然后从左向右计算每个位置结束的hash值由多少是之前没有出现过的(map判重)。
Input
The input contains a string s1 … sn 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 s1 … si minus the number of palindrome substrings of the prefix s1 … si−1. The first number in the output should be one.Sample
input | output |
---|---|
abbbba | 111111 |
Notes
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).Problem Author: Mikhail Rubinchik (prepared by Kirill Borozdin)
Problem Source: Ural FU Dandelion contest. Petrozavodsk training camp. Summer 2014
题意:问从左向右,每次加入一个字符,新增加了多少个回文串(之前未出现过)。
思路:先用马拉车算法,得到每一个回文串的结束位置,以及对应的hash值(vector保存)。然后从左向右计算每个位置结束的hash值由多少是之前没有出现过的(map判重)。
相关文章推荐
- Ural 2040 Palindromes and Super Abilities 2 回文自动机
- URAL 2040 Palindromes and Super Abilities 2 (Palindromic Tree)
- URAL 2040 Palindromes and Super Abilities 2(回文树)
- URAL 2040 Palindromes and Super Abilities 2
- URAL 2040 Palindromes and Super Abilities 2(回文树)
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
- URAL 2040 Palindromes and Super Abilities 2
- Ural 2040 Palindromes and Super Abilities 2
- Ural 2040. Palindromes and Super Abilities 2 回文自动机
- URAL2040-Palindromes and Super Abilities 2
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
- 【ural】1960. Palindromes and Super Abilities【Palindromic Tree】
- URAL 1960 Palindromes and Super Abilities (Palindromic Tree)
- URAL 1960- Palindromes and Super Abilities (回文树)
- ural 1960 Palindromes and Super Abilities 题解
- URAL 1960 Palindromes and Super Abilities (回文树)
- URAL - 1960 Palindromes and Super Abilities
- URAL1960 Palindromes and Super Abilities
- 【后缀回文自动机】 URAL 1960 Palindromes and Super Abilities