#P15696. [2018 KAIST RUN Spring] QueryreuQ

[2018 KAIST RUN Spring] QueryreuQ

题目描述

A string is palindrome, if the string reads the same backward and forward. For example, strings like “a”, “aa”, “appa”, “queryreuq” are all palindromes.

For given empty string SS, you should process following two queries:

  1. Add a lower case alphabet at the back of SS.
  2. Remove a character at the back of SS.

After processing a query, you should count the number of palindrome substring in SS. For string SS and integers ii, jj (1ijS1 \le i \le j \le |S|), S[i,j]S[i, j] represents a substring from iith to jjth character of SS. You should print out the number of integer pairs (i,j)(i, j) where S[i,j]S[i, j] is palindrome.

输入格式

Input consists of two lines.

In the first line, QQ, the number of queries is given.

In the second line, the query is given as string of length QQ. iith character KiK_i denotes the iith query. KiK_i is ‘-’ or lower case alphabet (‘a’, ‘b’, …, ‘z’) (without quotes).

If the character is ‘-’, you should remove a character at the back of SS. If the character is lower case alphabet, you should add a character KiK_i at the back of SS.

It is guaranteed that length of SS is always positive after the query.

输出格式

Print out QQ space-separated integers in the first line. ii-th integer should be the answer of the iith query.

17
queryreuq---------
1 2 3 4 5 7 9 11 13 11 9 7 5 4 3 2 1

提示

Constraints

  • 1Q10,0001 \le Q \le 10,000