BZOJ2844: albus就是要第一个出场

Description

f(空集) = 0
f(T) = XOR A[t] , 对于一切t属于T

3
1 2 3
1

Sample Output

3

【Hint】

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

Source

#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
inline char Getchar() {
}
}
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=100010;
int n,m,A[maxn],xp[maxn];
void gauss() {
int i,k=0;
dwn(j,30,0) {
for(i=k+1;i<=n;i++) if(A[i]>>j&1) break;
if(i>n) continue;
swap(A[i],A[++k]);
for(i=1;i<=n;i++) if(i!=k&&(A[i]>>j&1)) A[i]^=A[k];
}
m=n-k;n=k;
}
int main() {
gauss();
if(!x) puts("1");
else {
int cur=0;
rep(i,1,n) if((cur^A[i])<x) {
(ans+=xp[n-i])%=10086;
cur^=A[i];
}
ans=(ans+1)*xp[m]%10086;
printf("%d\n",(ans+1)%10086);
}
return 0;
}


posted @ 2016-04-12 12:44  wzj_is_a_juruo  阅读(163)  评论(0编辑  收藏  举报