P5679 [GZOI2017]等差子序列 bitset 统计小值域
EnofTaiPeople · · 题解
怎么好多人都要卡空间,还有的
如何让空间复杂度低于线性?我甚至不需要开数组,两个 bitset 就够了,于是空间复杂度为
具体的,如果
此处开一个 bitset 记录 bitset 只需要将前一个 bitset 左移 bitset 内找到 YES,否则为 NO。
代码不到
#include<bits/stdc++.h>
using namespace std;
const int N=60005,C=20001;
bitset<N>f,g;
int T,n,ans;
int main(){
ios::sync_with_stdio(false);
cin>>T;int i,x,y;
while(T--){
cin>>n,f.reset(),g.reset();
for(i=1,ans=0;i<=n;++i){
cin>>x;
if(f[x])ans=1;
f|=(g<<(x+x))>>C;
g[C-x]=1;
}puts(ans?"YES":"NO");
}return 0;
}