# BZOJ 2844: albus就是要第一个出场

## 2844: albus就是要第一个出场

Time Limit: 6 Sec  Memory Limit: 128 MB
Submit: 1169  Solved: 496
[Submit][Status][Discuss]

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<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;

const int maxn=100000+5,mod=10086;

int n,q,cnt,a[maxn],b[maxn];

int ans;

inline int power(int x,int y){
int res=1;
while(y){
if(y&1)
(res*=x)%=mod;
(x*=x)%=mod,y>>=1;
}
return res;
}

inline void xor_gauss(void){
cnt=0;
for(int i=1;i<=n;i++){
for(int j=n;j>i;j--)
if(a[j]>a[i])
swap(a[i],a[j]);
if(a[i])
cnt++;
else
break;
for(int j=31;j>=0;j--)
if((a[i]>>j)&1){
b[i]=j;
for(int k=1;k<=n;k++)
if(i!=k&&(a[k]>>j)&1)
a[k]^=a[i];
break;
}
}
}

signed main(void){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
xor_gauss();
scanf("%d",&q);
ans=0;
for(int i=1;i<=cnt;i++)
if((q>>b[i])&1)
q^=a[i],(ans+=power(2,cnt-i))%=mod;
printf("%d\n",(ans*power(2,n-cnt)%mod+1)%mod);
return 0;
}


By NeighThorn

posted @ 2017-02-22 23:38  NeighThorn  阅读(347)  评论(1编辑  收藏  举报