The only difference between easy and hard versions is constraints.

You are given a sequence a consisting of 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 and b, a can be equal b) and is as follows: [a,a,…,ax,b,b,…,by,a,a,…,ax]. There x,y are integers greater than or equal to 0. For example, sequences [], [2], [1,1], [1,2,1], [1,2,2,1] and [1,1,2,1,1] are three block palindromes but [1,2,3,2,1], [1,2,1,2,1] and [1,2] are not.

Your task is to choose the maximum by length subsequence of a that is a three blocks palindrome.

You have to answer t independent test cases.

Recall that the sequence t is a a subsequence of the sequence s if t can be derived from s by removing zero or more elements without changing the order of the remaining elements. For example, if s=[1,2,1,3,1,2,1], then possible subsequences are: [1,1,1,1], [3] and [1,2,1,3,1,2,1], but not [3,2,3] and [1,1,1,1,2].
View Code

相关文章:

  • 2021-12-25
  • 2021-12-28
  • 2021-05-15
  • 2021-04-16
  • 2021-09-17
  • 2021-12-24
  • 2021-11-29
  • 2021-06-17
猜你喜欢
  • 2021-10-04
  • 2022-02-09
  • 2022-12-23
  • 2022-03-10
  • 2021-07-09
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案