#x1074. Fedya the Potter Strikes Back
Fedya the Potter Strikes Back
Fedya the Potter Strikes Back
题面翻译
给定一个字符串 和一个序列 ,初始时它们都为空。
你需要在线完成 次操作。每次操作在 后面添加一个字符 ,在序列 后面添加一个数字 。二者均加密。
加密规则如下:设 为上一个查询的答案,初始值为 。将 按字典序后移 位,将 改成 ,其中 。特别地,定义 z
后移一位为 a
。
定义一个子区间 的可疑度为: 若子串 和前缀 相同,则其可疑度为 。否则其可疑度为 。
每次操作后,你都要求出当前的串的所有子区间的可疑度之和。
,, 为小写字母。
题目描述
Fedya has a string , initially empty, and an array , also initially empty.
There are queries to process, one at a time. Query consists of a lowercase English letter and a nonnegative integer . First, must be appended to , and must be appended to . The answer to the query is the sum of suspiciousnesses for all subsegments of , .
We define the suspiciousness of a subsegment as follows: if the substring of corresponding to this subsegment (that is, a string of consecutive characters from -th to -th, inclusive) matches the prefix of of the same length (that is, a substring corresponding to the subsegment ), then its suspiciousness is equal to the minimum in the array on the subsegment. Otherwise, in case the substring does not match the corresponding prefix, the suspiciousness is .
Help Fedya answer all the queries before the orderlies come for him!
输入格式
The first line contains an integer — the number of queries.
The -th of the following lines contains the query : a lowercase letter of the Latin alphabet and an integer .
All queries are given in an encrypted form. Let be the answer to the previous query (for the first query we set this value equal to ). Then, in order to get the real query, you need to do the following: perform a cyclic shift of in the alphabet forward by , and set equal to , where is the bitwise exclusive "or", is the bitwise "and", and .
输出格式
Print lines, -th line should contain a single integer — the answer to the -th query.
样例 #1
样例输入 #1
7
a 1
a 0
y 3
y 5
v 4
u 6
r 8
样例输出 #1
1
2
4
5
7
9
12
样例 #2
样例输入 #2
4
a 2
y 2
z 0
y 2
样例输出 #2
2
2
2
2
样例 #3
样例输入 #3
5
a 7
u 5
t 3
s 10
s 11
样例输出 #3
7
9
11
12
13
提示
For convenience, we will call "suspicious" those subsegments for which the corresponding lines are prefixes of , that is, those whose suspiciousness may not be zero.
As a result of decryption in the first example, after all requests, the string is equal to "abacaba", and all , that is, the suspiciousness of all suspicious sub-segments is simply equal to . Let's see how the answer is obtained after each request:
1. = "a", the array has a single subsegment — , and the corresponding substring is "a", that is, the entire string , thus it is a prefix of , and the suspiciousness of the subsegment is .
2. = "ab", suspicious subsegments: and , total .
3. = "aba", suspicious subsegments: , , and , total .
4. = "abac", suspicious subsegments: , , , and , total .
5. = "abaca", suspicious subsegments: , , , , , and , total .
6. = "abacab", suspicious subsegments: , , , , , , , and , total .
7. = "abacaba", suspicious subsegments: , , , , , , , , , , and , total .
In the second example, after all requests = "aaba", .
1. = "a", suspicious subsegments: (suspiciousness ), totaling .
2. = "aa", suspicious subsegments: ( ), ( ), ( ), totaling .
3. = "aab", suspicious subsegments: ( ), ( ), ( ), ( ), totaling .
4. = "aaba", suspicious subsegments: ( ), ( ), ( ), ( ), ( ), ( ), totaling .
In the third example, from the condition after all requests = "abcde", .
1. = "a", suspicious subsegments: ( ), totaling .
2. = "ab", suspicious subsegments: ( ), ( ), totaling .
3. = "abc", suspicious subsegments: ( ), ( ), ( ), totaling .
4. = "abcd", suspicious subsegments: ( ), ( ), ( ), ( ), totaling .
5. = "abcde", suspicious subsegments: ( ), ( ), ( ), ( ), ( ), totaling .