#P6114. 【模板】Lyndon 分解

【模板】Lyndon 分解

Problem Description

This is a template problem.

Given a string ss consisting of lowercase English letters, split it into several parts s=s1s2s3sms = s_1 s_2 s_3 \cdots s_m, such that each sis_i is a Lyndon Word, and 1i<m:sisi+1\forall 1 \le i < m: s_i \ge s_{i+1}. Output the positions of the right endpoints of the lengths of the strings from s1s_1 to sms_m. The positions are numbered from 11 to nn.

A string ss is a Lyndon Word\text{Lyndon Word} if and only if ss is the smallest string among all its suffixes.

To reduce the output size, you only need to output the XOR of all right endpoints.

Input Format

One line containing a string ss of length nn, consisting only of lowercase English letters.

Output Format

One line containing an integer, representing the XOR of all right endpoints.

ababa

3

bbababaabaaabaaaab

23

Hint

The answer for the first sample is 2 4 5.

The answer for the second sample is 1 2 4 6 9 13 18.

  • For 20%20\% of the testdata, 1n10001 \le n \le 1000 is guaranteed.
  • For 100%100\% of the testdata, 1n5×106+11 \le n \le 5 \times 10^6 + 1 is guaranteed.

Translated by ChatGPT 5