首页 > 其他分享 >【板子】线性基

【板子】线性基

时间:2024-01-26 21:15:54浏览次数:26  
标签:working int ll long 板子 62 ans 线性

//lg p3812
#include<bits/stdc++.h>
using namespace std;

#define ll unsigned long long

ll d[100];
int n;

void Insert(ll x)
{
	for(int i=62;i>=1;i--)
	{
		if(!(x>>(i-1))) continue;
		if(!d[i])
		{
			d[i]=x;
			return ;
		}
		else 
		{
			x^=d[i];
		}
	}
}

ll FindMax()
{
	ll ans=d[62];
	for(int i=62;i>=1;i--)
	{
		if((ans^d[i])>ans)
		{
			ans^=d[i];
		}
	}
	return ans;
}

int main()
{
	// freopen("working.in","r",stdin);
	// freopen("working.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		Insert(x);
	}
	cout<<FindMax();
	return 0;
}

标签:working,int,ll,long,板子,62,ans,线性
From: https://www.cnblogs.com/yeyou26/p/17990714

相关文章

  • 【板子】后缀自动机(SAM)
    //lg3804//Copyrightyeyou26//注意:这道题不是纯纯的后缀自动机,main函数有一点额外处理#include<bits/stdc++.h>usingnamespacestd;#definelllonglong#defineN(int(2e6+6))intfa[N];intch[N][28];intlen[N];intcnt[N];llans;intidx=1;intnp=1;str......
  • 【板子】冒泡/选择/插入 排序
    #include<bits/stdc++.h>usingnamespacestd;#defineN101inta[N];voidsort_mp(){for(inti=1;i<100;i++){for(intj=1;j<100;j++){if(a[j]>a[j+1]){swap(a[j],a[j+1]);......
  • 【板子】高斯约旦消元法(可判解)
    //lg2455#include<bits/stdc++.h>usingnamespacestd;constdoubleeps=0.000001;constintN=105;doublea[N][N];intn;intnowline=1;//存储当前行voidGaussJordan(){ for(inti=1;i<=n;i++)//枚举列若方程有唯一解则与枚举行列等效 { intmxline=no......
  • 【板子】快读/快写
    //double快读inlinevoidReadouble(double&ans){ ans=0; doubley=1.0; boolflag=0; charch=getchar(); while(!isdigit(ch)&&~ch) { flag|=(ch=='-'); ch=getchar(); } while(isdigit(ch)&&~ch) { ans=ans*10+(ch^48);......
  • 【板子】快速排序
    #include<bits/stdc++.h>usingnamespacestd;inta[114514];voidQuicksort(intl,intr);intmain(){freopen("working.in","r",stdin);freopen("working.out","w",stdout);intn;cin>>n;......
  • 【板子】归并排序
    #include<bits/stdc++.h>usingnamespacestd;constintN=1e6+6;intn;inta[N];intb[N];voidMergesort(intl,intr);longlongcnt;intmain(){freopen("working.in","r",stdin);freopen("working.out",&......
  • 【板子】树状数组(BIT)
    //lg1908求逆序对//Copyrightyeyou26#include<bits/stdc++.h>usingnamespacestd;#definelllonglongconstintN=(int)1e6+6;llsum;intn;structData{intorigin;intls;intid;}data[N];boolcmporigin(Datax,Datay){r......
  • 【板子】强连通分量(SCC)
    //强连通分量//lg2863求强连通分量的数量#include<bits/stdc++.h>usingnamespacestd;constintN=(int)2e4+4;intwhere[N];//这个点在哪个scc里intscccnt;intsccsize[N];intlow[N],dfn[N],idx;boolinstk[N];stack<int>stk;vector<int>e[N];intn,m;......
  • 【板子】字符串哈希
    //lgp3370//Copyrightyeyou26#include<bits/stdc++.h>usingnamespacestd;#defineullunsignedlonglongstrings;intn;constullp=998244353;ullnow_hash;ullv[100005];intcnt;intans;voidget_hash();voiddo_compare();voidinit()......
  • 【板子】字符串最小表示法
    //lgp1368//Copyrightyeyou26#include<bits/stdc++.h>usingnamespacestd;longlonga[600005];intn;voidinit();voidsolve(){inti=1,j=2,k=0;while(i<=n&&j<=n){k=0;while(a[i+k]==a[j+k]&&am......