思想:
线性基和快速幂
代码:
#include<iostream> #include<stdio.h> #include<cstring> #include<vector> using namespace std; typedef long long ll; const int mod = 1e9+7; ll base[62],rem[100005],baser[62],num[100005]; int n; bool insert(ll t,ll *base){ int i; for(int i= 60;i>=0;i--){ if(t&(1ll<<i)){ if(!base[i]){ base[i] =t; return true; } else t = t^base[i]; } } return false; } ll qpow(ll x,ll pow){ ll sum = 1; while(pow){ if(pow%2==1) sum=sum*x%mod; x=x*x%mod; pow>>=1; } return sum; } bool check(ll t,ll *base){ for(int i=60;i>=0;i--){ if(t&(1ll<<i)) t^=base[i]; } return t ==0; } int main(){ while(~scanf("%d",&n)){ int i,j,flag = 0; ll ans = 0; vector<ll> index; memset(base,0,sizeof(base)); memset(rem,0,sizeof(rem)); memset(baser,0,sizeof(baser)); for(i=1;i<=n;i++){ scanf("%lld",&num[i]); if(!insert(num[i],base)) rem[++flag] = num[i]; else index.push_back(i); } if(flag==0){ cout<<"0"<<endl; return 0; } ans = (ans+(ll)flag*qpow(2,flag-1)%mod)%mod; for(int i=1;i<=flag;i++) insert(rem[i],baser); for(i=0;i<index.size();i++){ ll basedr[62],x = num[index[i]]; for(j=0;j<=60;j++) basedr[j] = baser[j]; for(j=0;j<index.size();j++){ if(j!=i) insert(num[index[j]],basedr); } if(check(x,basedr)) ans = (ans+qpow(2,flag-1))%mod; } cout<<ans<<endl; } return 0; }
借鉴博客:
https://blog.csdn.net/liufengwei1/article/details/96571038
https://blog.csdn.net/weixin_43702895/article/details/97683338