题目传送门
/*
递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理
判断ai-2, ai-1, ai是否是等差(比)数列,能在O(n)时间求出最长的长度
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
ll a[MAXN];
int dp1[MAXN], dp2[MAXN];
int main(void) { //HDOJ 5328 Problem Killer
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
for (int i=; i<=n; ++i) scanf ("%I64d", &a[i]);
if (n <= ) printf ("%d\n", n);
else {
for (int i=; i<=n; ++i) dp1[i] = dp2[i] = ;
int ans = ;
for (int i=; i<=n; ++i) {
if (a[i-] + a[i] == a[i-] * ) dp1[i] = dp1[i-] + ;
if (a[i-] * a[i] == a[i-] * a[i-]) dp2[i] = dp2[i-] + ;
ans = max (ans, max (dp1[i], dp2[i]));
}
printf ("%d\n", ans);
}
}
return ;
}