题目描述
The only difference between easy and hard versions is constraints.
You are given a sequence a a a consisting of n n n positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are a a a and b b b , a a a can be equal b b b ) and is as follows: [a,a,…,a⏟x,b,b,…,b⏟y,a,a,…,a⏟x] [underbrace{a, a, dots, a}_{x}, underbrace{b, b, dots, b}_{y}, underbrace{a, a, dots, a}_{x}] [xa,a,…,a,yb,b,…,b,xa,a,…,a] . There x,y x, y x,y are integers greater than or equal to 0 0 0 . For example, sequences [] [] [] , [2] [2] [2] , [1,1] [1, 1] [1,1] , [1,2,1] [1, 2, 1] [1,2,1] , [1,2,2,1] [1, 2, 2, 1] [1,2,2,1] and [1,1,2,1,1] [1, 1, 2, 1, 1] [1,1,2,1,1] are three block palindromes but [1,2,3,2,1] [1, 2, 3, 2, 1]