题目大意:给出n的排列,求是否存在长度大于等于3的等差数列
题解:显然只需要求长度等于3的等差数列
枚举等差中项
b,判断是否存在a+c=2b,其中a在b之前,c在b之后
b
,
判
断
是
否
存
在
a
+
c
=
2
b
,
其
中
a
在
b
之
前
,
c
在
b
之
后
两个bitset维护左边的20000-a和右边的c,如果把左边右移20000-2b后与右边的与不为0则存在
我的收获:bitset大法吼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm>
using namespace std;
const int M=10005;
int T,n,a[M];
bitset<20005> b,c;
void work()
{
for(int i=1;i<=n;i++)
{
c[a[i]]=0;
if(((b>>(20000-a[i]*2))&c).any()){puts("Y");return ;}
b[20000-a[i]] = 1;
}
puts("N");
}
void init()
{
cin>>n;b.reset();c.reset();
for(int i=1;i<=n;i++) cin>>a[i],c[a[i]]=1;
}
int main()
{
cin>>T;
while(T--) init(),work();
return 0;
}