简述题意:
时间复杂度:O(T*n^2)
难度:NOIP
算法:据说正解是 线段树/树状数组 维护 hash
但我是用循环水过的,逃......
我们只需要找到序列长度为3的即可!
我们考虑将读入的这个点作为一个等差序列子序列的中间元素x,
那么我们枚举它左边的元素a(<x),通过等差序列的性质,就可以找到它右边的元素b(>x)()
因为我们还需要保证下标单调递增,所以我们对所有已经读入的数打标记,if(vis[x]^vis[j]),那么说明应输出“Y”
注意:见代码。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#define ll long long
#define N 10005
using namespace std;
bool vis[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
bool fla=0;
scanf("%d",&n);
memset(vis,0,sizeof(vis));
for(int i = 1;i <= n;++i)
{
int a;
scanf("%d",&a);
if(fla) continue;//这里不能break,不然你的读入怎么办???
vis[a]=1;
for(int j = a-1;j > 0;--j)
{
int x=a*2-j;
if(x>n) continue;
if(vis[x]^vis[j])
{
fla=1;
break;
}
}
}
fla==1?puts("Y"):puts("N");
}
return 0;
}