More than 2019 cattle off summer school camp (first): XOR (linear base)

Meaning of the questions: given array, or up to find all the different sets and the size of ones and zeros.

Idea: Because it is a collection of size, we consider each element contributing replaced in the number of collection. Mr. linear group.

For a linear group is not inserted element x, the contribution is 2 ^ (N-base-1), then x selective because, regardless of other elements selected from the group of non-selected or not, can be adjusted such that the group is 0 and the exclusive OR.

Insertion element linear group x, we also consider this, in addition to the number of its N-1 generate a linear group. It can also be considered a contribution. Here now little optimization, the non-group elements into a beginning of the linear pre-group, so that new linear groups up soon.

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int maxn=2000010;
const int Mod=1e9+7;
ll a[maxn],b[maxn],c[maxn],used[maxn]; int tot;
int qpow(int a,int x){
    int res=1; while(x){
        if(x&1) res=1LL*res*a%Mod;
        x>>=1; a=1LL*a*a%Mod;
    } return res;
}
bool add(ll x,ll base[])
{
    rep2(i,63,0) {
        if(x&(1LL<<i)){
            if(!base[i]){ base[i]=x; return true;}
            x^=base[i];
        }
    }
    return false;
}
int main()
{
    int N,ans=0;  ll x;
    while(~scanf("%d",&N)){
       rep(i,0,63) a[i]=b[i]=c[i]=0; tot=0;
       rep(i,1,N) {
          scanf("%lld",&x);
          if(add(x,a)) used[++tot]=x;
          else add(x,b);
       }
       if(tot<N) ans=1LL*qpow(2,N-tot-1)*(N-tot)%Mod;
       rep(i,1,tot){
           rep(j,0,63) c[j]=b[j];
           rep(j,1,tot) if(i!=j) add(used[j],c);
           if(!add(used[i],c)) (ans+=qpow(2,N-tot-1))%=Mod;
       }
       printf("%d\n",ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hua-dong/p/11463064.html