BZOJ_2844_albus就是要第一个出场_线性基

BZOJ_2844_albus就是要第一个出场_线性基

3

1 2 3

1

Sample Output

3

N = 3, A = [1 2 3]

S = {1, 2, 3}

2^S = {空, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}

f(空) = 0

f({1}) = 1

f({2}) = 2

f({3}) = 3

f({1, 2}) = 1 xor 2 = 3

f({1, 3}) = 1 xor 3 = 2

f({2, 3}) = 2 xor 3 = 1

f({1, 2, 3}) = 0

B = [0, 0, 1, 1, 2, 2, 3, 3]

HINT

1 <= N <= 10,0000

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod=10086;
int qp(int x,int y) {
int re=1; for(;y;y>>=1,x=x*x%mod) if(y&1) re=re*x%mod; return re;
}
int n,b[40],a[40];
void insert(int x) {
int i;
for(i=30;i>=0;i--) {
if(x&(1<<i)) {
if(b[i]) x^=b[i];
else {
b[i]=x; return ;
}
}
}
}
void Guass() {
int i,j;
for(i=30;i>=0;i--) {
if(b[i]) {
for(j=30;j>=0;j--) {
if(i!=j&&(b[j]&(1<<j))) b[j]^=b[i];
}
}
}
}
int main() {
scanf("%d",&n);
int i,x;
for(i=1;i<=n;i++) scanf("%d",&x),insert(x);
Guass();
int Q;
scanf("%d",&Q);
int k=0;
for(i=0;i<=30;i++) if(b[i]) a[++k]=i;
int re=0;
for(i=1;i<=k;i++) {
if(Q&(1<<(a[i]))) {
re=(re+(1<<(i-1)))%mod;
}
}
printf("%d\n",(re*qp(2,n-k)%mod+1)%mod);
}


posted @ 2018-06-15 13:55  fcwww  阅读(186)  评论(0编辑  收藏  举报