版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fanhansheng/article/details/82557290
线性基:
若干数的线性基是一组数a1,a2,...ana1,a2,...an,其中axax的最高位的11在第xx位。
通过线性基中元素xor出的数的值域与原来的数xor出数的值域相同。
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 100005;
typedef long long LL;
LL p[105];
void Insert(LL x)
{
for(LL i=50;i>=0;--i)
{
if((x>>i)&1)
{
if(!p[i])
{
p[i]=x;
break;
}
x^=p[i];//如果某数位已有数组中某个数的高位1可以表示,就要除去正在加入的数位的1.目的是使得每一位的1只由一个数提供一次。
}
}
}
int main()
{
int n;
LL c;
scanf("%d", &n);
for(int i=0;i<n;++i)
{
scanf("%lld", &c);
Insert(c);
}
int q;
scanf("%d", &q);
while(q--)
{
LL x, y;
scanf("%lld %lld", &x, &y);
x^=y;
for(LL i=50;i>=0;--i)
{
if((x>>i)&1)x^=p[i];
}
if(x)
puts("NO");
else
puts("YES");
}
return 0;
}