#P16448. [XJTUPC 2026] Triple Mirror: The Harmony of Repetition

    ID: 18479 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>二分哈希 hashing2026高校校赛

[XJTUPC 2026] Triple Mirror: The Harmony of Repetition

Background

:::epigraph[------ Palindrom] Blankness is the only language that never lies. :::

Problem Description

You are playing a game called “Mirror Fragments”. In this game, you travel through an ancient ruin made of mirrors. The inscriptions in the ruin change in strange ways inside the mirrors.

You once observed that after a character sequence is reflected by a mirror, what you see looks like it is “unfolded”, and every character appears twice. For example, the sequence hua\tt{hua} appears in the mirror as aauuhh\tt{aauuhh}. If you look from the side and see both the real object outside the mirror and the virtual image in the mirror at the same time, they overlap in order, forming aauuhhhua\tt{aauuhhhua}. This overlapped whole is the complete mapping of the sequence.

You are very interested in this mapping. Now you are given a string S=s1s2⋯snS=s_1s_2\cdots s_n of length nn. Please count how many non-empty substrings T=S[l…r]T=S[l\dots r] (where S[l…r]=slsl+1sl+2⋯srS[l\dots r]=s_ls_{l+1}s_{l+2}\cdots s_r) can be an image of such a mapping. Specifically, a substring T=t1t2⋯tmT=t_1t_2\cdots t_m of length mm must satisfy the following conditions:

  • mm is a multiple of 33.
  • Let m=3km = 3k. Then for all i=1,2,…,ki=1,2,\dots,k, we have t2i−1=t2i=t3k−i+1t_{2i-1}=t_{2i}=t_{3k-i+1}.

In other words, TT must be of the form:

$$a_1a_1a_2a_2a_3a_3\cdots a_{k}a_{k}a_{k}a_{k-1}a_{k-2}\cdots a_1$$

where a1,a2,…,aka_1, a_2, \dots, a_k is some character sequence.

Note that for two substrings S[l…r]=slsl+1sl+2⋯srS[l\dots r]=s_ls_{l+1}s_{l+2}\cdots s_r and S[l′…r′]=sl′sl′+1sl′+2⋯sr′S[l'\dots r']=s_{l'}s_{l'+1}s_{l'+2}\cdots s_{r'}, they are considered two different substrings and should be counted twice if and only if l≠l′l\ne l' or r≠r′r\ne r'.

Input Format

The input consists of one line containing only a string SS (the length ∣S∣|S| satisfies 1≤∣S∣≤2×1051\le |S|\le 2\times 10^5). It is guaranteed that SS consists only of lowercase Latin letters $\texttt{a}, \texttt{b}, \texttt{c}, \cdots, \texttt{z}$.

Output Format

Output one line containing one integer, the number of substrings that satisfy the conditions.

aaaaaa
5
aaaaaabbbcccccc
11

Hint

Translated by ChatGPT 5