Firstly, the Manacher algorithm of palindrome string is used to find the length of palindrome string centered on the first and the i+1 points, and recorded in array C such as 10 9 8 8 9 10 10 9 8 We run the Manacher to find the first point and the first i+1 point of the palindrome string length 0 0 6 0 0 6 0 0 0

Two 8 is the center, 10 9 8 8 9 10 is a palindrome string, the length is 6. Two 10 is the center, 8 9 10 10 9 8 is a palindrome string, the length is 6.

To meet the requirements of the topic, you need to make two adjacent palindrome strings, sharing the middle part, such as the top two strings, sharing 8 9 10 this part. That is, the left side of the palindrome string half of the length, to greater than equal to the length of the shared part, the right palindrome is the same. Because we have recorded the length of the palindrome string centered on the point I and i+1, then the problem can be converted to two numbers a[i],a[i+x "x", satisfying a[i]/2>=x and a[i+x]/2>=x, requiring X to be as large as possible

This can be maintained with a set, at the beginning of the collection is empty, then take the largest element in the array of a, put its subscript into the set, each taking out an element, and then the collection of two points to find smaller than I+A[I]/2, but the largest element, update the answer. Then look in the collection for larger, but smallest elements than I-A[I]/2, to update the answer.

The answer is 3*an.

Hotaru ' s problemTime

** limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)**

Total submission (s): 1513 Accepted Submission (s): 555

Problem Descriptionhotaru Ichijou recently is addicated to math problems. Now she's playing with N-sequence.

Let's define N-sequence, which is composed with three parts and satisfied with the following condition:

1. The first part of the same as the thrid part,

2. The first part and the second part is symmetrical.

For example, the sequence 2,3,4,4,3,2,2,3,4 are a n-sequence, which the first part 2,3,4 are the same as the Thrid Part 2, 3, 4, the first part 2,3,4 and the second part 4,3,2 is symmetrical.

Give you n positive intergers, your task was to find the largest continuous sub-sequence, which is n-sequence.

Inputthere is multiple test cases. The first line of input contains an integer T (t<=20), indicating the number of test cases.

For each test case:

The first line of input contains a positive integer N (1<=n<=100000), the length of a given sequence

The second line includes N non-negative integers, each interger is no larger than ten 9 , descripting a sequence.

Outputeach case contains only one line. Should start with ' case #i: ', with I implying the case number, followed by a integer, the largest length of n-se Quence.

We guarantee the sum of all answers are less than 800000.

Sample Input

1102 3 4 4 3 2 2 3 4 4

Sample Output

Case #1:9

Source2015 multi-university Training Contest 7

/* ***********************************************author:ckbosscreated time:2015 August 12 Wednesday 12:44 58 seconds file Name : hdoj5371.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <set> using namespace Std;const int maxn=100100;int n;int str[maxn],ans[maxn*3];int p[maxn*3],pos,tot;void Pre () {tot=1; memset (ans,0,sizeof (ans)); ans[0]=-2;for (int i=0;i<n;i++) {ans[tot]=-1; tot++;ans[tot]=str[i]; tot++;} ans[tot]=-1;tot++;} void Manacher () {Pos=-1;memset (p,0,sizeof (P)); int mx=-1,mid=-1;int len=tot;for (int i=0;i<len;i++) {int j=-1;if (i <MX) {j=2*mid-i;p[i]=min (p[j],mx-i);} else P[i]=1;while (I+p[i]<len&&ans[i+p[i]]==ans[i-p[i]]) p[i]++;if (p[i]+i>mx) {mx=p[i]+i; mid=i;}} struct Node{int Pos,len; Node () {}node (int _pos,int _len):p os (_pos), Len (_len) {}void toString () {printf ("pos:%d len:%d\n", Pos,len);} BOOL operator< (CONST node& Node) Const{return len<node.len;}}; int main () {//freopen ("In.txt", "R", stdin),//freopen ("OUT.txt", "w", stdout), int cas=1,t_t;scanf ("%d", &t_t); while (t_t--) {scanf ("%d", &n), for (int i=0;i<n;i++) scanf ("%d", Str+i);p re (); Manacher ();p riority_queue< node> q;for (int i=0;i<tot;i++) {if (ans[i]==-1) {node node (I/2,P[I]/2); Q.push (node);}} Set<int> st;set<int>::iterator it;int as=0;while (!q.empty ()) {Node u=q.top (); Q.pop (); if (St.size () ==0) { St.insert (U.pos); Continue }int Left=u.pos-u.len;it=st.lower_bound (left); if (*it<left| | It==st.end ()) it--;if (*it>=left) {As=max (as,u.pos-*it);} int Right=u.pos+u.len;it=st.lower_bound (right); if (*it>right| | It==st.end ()) it--;if (*it<=right) {As=max (as,*it-u.pos);} St.insert (U.pos);} printf ("Case #%d:%d\n", cas++,as*3);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj 5371 Hotaru ' s problem manacher+ priority queue + two points