http://acm.hdu.edu.cn/showproblem.php?pid=4513
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include<cstdio> #include<string> #include<cstring> #include <stdio.h> #include <string.h> using namespace std; int a[100009] , b[200009]; int p[200009]; int num; int main() { int t ; scanf("%d" , &t); while(t--) { int l ; scanf("%d" , &l); for(int i = 0 ; i < l ; i++) { scanf("%d" , &a[i]); } int len = 0 ; b[len++] = -1; b[len++] = -1 ; for(int i = 0 ; i < l ; i++) { b[len++] = a[i]; b[len++] = -1 ; } int mx = -1 , mid , ans = 0; for(int i = 1 ; i < len ; i++) { if(mx > i) { p[i] = min(p[2*mid-i] , mx - i); } else { p[i] = 1 ; } while(b[i-p[i]] == b[i+p[i]] && b[i - p[i] + 2] >= b[i - p[i]])//从中间往两边递减 { p[i]++; } if(mx < p[i] + i) { mid = i ; mx = p[i] + i; } ans = max(ans , p[i] - 1); } printf("%d\n" ,ans); } return 0 ; }
原文:https://www.cnblogs.com/nonames/p/11296260.html