题目链接:

①:洛谷P3812
②:牛客练习赛26D
参考博客:https://www.cnblogs.com/olinr/p/9477787.html
这位童鞋写得很好~
求异或最大值

#include"bits/stdc++.h"
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const int MOD=1e9+7;
const int bit=62;
LL Line[bit+5];
void Insert(LL x)
{
	for(int j=bit; j>=0; j--)
	{
		if(x&(1LL<<j))//这里注意是1LL,容易错
		{
			if(Line[j]==0)//如果这一行还全部是0
			{
				Line[j]=x;
				return ;
			}
			else x^=Line[j];//还有这里,是把进来的数x的这一位异或掉
		}
	}
}
LL getMax()
{
	LL res=0;
	for(int i=bit; i>=0; i--)
	{
		if((res^Line[i])>res)res^=Line[i];
	}
	return res;
}
int main()
{
	int N;
	while(cin>>N)
	{
		memset(Line,0,sizeof Line);
		for(int i=1; i<=N; i++)
		{
			LL t;
			cin>>t;
			Insert(t);
		}
		cout<<getMax()<<endl;
	}
}

线性基的用处

①:就是求异或和最大
②:就是求这个只含01的方阵的秩
比如牛客上面的这道题:牛客练习赛49 E 筱玛爱游戏就是转换成线性基来做