luogu P3812 【模板】线性基

模板题。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

typedef long long LL;
LL a[100];
int n;

void Insert(LL x)
{
	for (int i=60;i>=0;i--)
		if(x&(1LL<<i))
			if(!a[i])
			{
				a[i]=x;
				break;
			}
			else
				x^=a[i];
}

LL Query_Max()
{
	LL now=0;
	for (int i=60;i>=0;i--)
		if(!(now&(1LL<<i)))
			now^=a[i];
	return now;
}

void init()
{
	scanf("%d",&n);
	LL x;
	for (int i=1;i<=n;i++)
		scanf("%lld",&x),Insert(x);
}

void work()
{
	printf("%lld\n",Query_Max());
}

int main()
{
	init();
	work();
	return 0;
}
posted @ 2020-05-06 21:44  With_penguin  阅读(84)  评论(0编辑  收藏  举报