题目链接
题解
线段树好题
我选择暴力
代码
// luogu-judger-enable-o2
#include<cstdio>
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9')c = getchar();
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
const int maxn = 10007;
int a[maxn],b[maxn];
int main() {
int t = read();
int n;
while(t --) {
n = read(); bool flag = false;
for(int i = 1;i <= n;++ i) a[i] = read(),b[a[i]] = i;
for(int i = 1;i <= n;++ i) {
for(int j = 1;j <= n;++ j) {
int k = a[i];
if(k + j + j <= n) if(b[k + j] > i && b[k + j + j] > b[k + j]) {flag = true;break;}
if(k - j - j > 0) if(b[k - j] > i && b[k - j - j] > b[k - j]) {flag = true;break;}
}
if(flag) break;
}
if(flag) puts("Y");
else puts("N");
for(int i = 1;i <= n;++ i) b[i] = 0;
}
return 0;
}