给你一个数组,求最长的非降序回文.
int N;
int s[MAXN],n[MAXN*2+5];
int p[MAXN*2+5];
int init(int *s){
int lena = N;
n[0]=-2;
n[1]=-1;
int j=2;
for(int i=0;i<lena;i++){
n[j++] = s[i];
n[j++] = -1;
}
n[j] = -1;
return j;
}
int mana(int *s,int nn){
memset(p,0,sizeof(p));
int maxlen = -1;
int id,mx=0;
for(int i=1;i<nn;i++){
int cc=1;
if(i<mx){
p[i] = min(p[2*id-i],mx-i);
}
else p[i]=1;
while(n[i-p[i]] == n[i+p[i]] && cc){
if(n[i-p[i]] < 0)p[i]++;
else if(n[i-p[i]]<=n[i+p[i]-2])p[i]++;
else cc=0;
}
if(i+p[i]>mx){
id = i;
mx = i+p[i];
}
maxlen = max(maxlen,p[i]);
}
return maxlen-1;
}
int main(){
int c;
scanf("%d",&c);
while(c--){
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%d",&s[i]);
}
int num = init(s);
printf("%d\n",mana(n,num));
}
return 0;
}