#abc290e. E - Make it Palindrome

E - Make it Palindrome

Score : 500500 points

问题描述

对于一个序列 XX,令 f(X)=f(X) = (将 XX 改造为回文串所需的最少元素修改次数)。

给定长度为 NN 的序列 AA,求 AA 中所有 连续 子数组的 f(X)f(X) 值之和。

这里,长度为 mm 的序列 XX 被称为回文串,当且仅当对于所有 1im1 \le i \le mXX 的第 ii 个元素与第 (m+1i)(m+1-i) 个元素相等。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

For a sequence XX, let f(X)=f(X) = (the minimum number of elements one must modify to make XX a palindrome).

Given a sequence AA of length NN, find the sum of f(X)f(X) over all contiguous subarrays of AA.

Here, a sequence XX of length mm is said to be a palindrome if and only if the ii-th and the (m+1i)(m+1-i)-th elements of XX are equal for all 1im1 \le i \le m.

Constraints

  • All values in the input are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1AiN1 \le A_i \le N

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer as an integer.

Sample Input 1

5
5 2 1 2 2

Sample Output 1

9
  • f(5)=0f(5) = 0
  • f(2)=0f(2) = 0
  • f(1)=0f(1) = 0
  • f(2)=0f(2) = 0
  • f(2)=0f(2) = 0
  • f(5,2)=1f(5,2) = 1
  • f(2,1)=1f(2,1) = 1
  • f(1,2)=1f(1,2) = 1
  • f(2,2)=0f(2,2) = 0
  • f(5,2,1)=1f(5,2,1) = 1
  • f(2,1,2)=0f(2,1,2) = 0
  • f(1,2,2)=1f(1,2,2) = 1
  • f(5,2,1,2)=2f(5,2,1,2) = 2
  • f(2,1,2,2)=1f(2,1,2,2) = 1
  • f(5,2,1,2,2)=1f(5,2,1,2,2) = 1

Therefore, the sought answer is 99.

update @ 2024/3/10 12:07:15