#P16315. [ICPC 2023 Jinan R] 基本子串结构
[ICPC 2023 Jinan R] 基本子串结构
Problem Description
After finishing the paper Faster Algorithms for Internal Dictionary Queries, Xiaoqingyu and Qiyi Hadron decided to create the following problem.
Let denote the longest common prefix of strings and , i.e., the largest integer such that and equals .
Xiaoqingyu gives you a non-empty string . Define $f(s) = \sum\limits_{i=1}^{n} \text{lcp}(s, \text{suf}(s, i))$, where denotes the suffix of starting from (i.e., ). Note that in this problem, the alphabet contains letters, not just .
For each , you need to answer the following query: if you must change to another different character (), choose the best character and compute the maximum value of , where .
Input Format
There are multiple test cases. The first line contains an integer denoting the number of test cases. For each test case:
The first line contains an integer (), the length of the string.
The second line contains integers (), where means the -th character of the string is the -th letter in the alphabet.
It is guaranteed that the sum of all over the test cases does not exceed .
Output Format
Let denote the maximum value of . To reduce the output size, for each test case output one integer on a single line, which is , where is the bitwise XOR operator.
2
4
2 1 1 2
12
1 1 4 5 1 4 1 9 1 9 8 10
15
217
Hint
For the first sample, we first compute .
- If we change to , then .
- If we change to or , then .
Therefore, .
Similarly, , , and . So the answer is $(7 \oplus 1) + (6 \oplus 2) + (6 \oplus 3) + (4 \oplus 4) = 15$.
Translated by ChatGPT 5