bzoj2844: albus就是要第一个出场

Description

已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2^S定义为S 所有子集构成的集合。

定义映射 f : 2^S -> Z

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

现在albus把2^S中每个集合的f值计算出来, 从小到大排成一行, 记为序列B(下标从1开始)。 给定一个数, 那么这个数在序列B中第1次出现时的下标是多少呢?

Input

第一行一个数n, 为序列A的长度。
接下来一行n个数, 为序列A, 用空格隔开。
最后一个数Q, 为给定的数.

Output

共一行, 一个整数, 为Q在序列B中第一次出现时的下标模10086的值.

Sample Input

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

其他所有输入均不超过10^9

 
见http://blog.csdn.net/popoqqq/article/details/39829237
 
code:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #define maxn 100005
 7 #define mod 10086
 8 using namespace std;
 9 char ch;
10 int n,m,q,a[maxn],ans;
11 bool ok;
12 void read(int &x){
13     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
14     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
15     if (ok) x=-x;
16 }
17 void gauss(){
18     int i,j,k;
19     for (i=30,k=1;i>=0;i--){
20         for (j=k;j<=n&&!(a[j]&(1<<i));j++);
21         if (j<=n){
22             swap(a[k],a[j]);
23             for (j=1;j<=n;j++) if (j!=k&&(a[j]&(1<<i))) a[j]^=a[k];
24             k++;
25         }
26     }
27     m=k-1;
28 }
29 int ksm(int a,int b){
30     int t=1;
31     for (;b;b>>=1){if (b&1) t=t*a%mod; a=a*a%mod;}
32     return t;
33 }
34 int main(){
35     read(n);
36     for (int i=1;i<=n;i++) read(a[i]);
37     gauss();
38     read(q),ans=0;
39     int now=0;
40     for (int i=1;i<=m;i++) if ((now^a[i])<q) ans+=ksm(2,m-i),ans%=mod,now^=a[i];
41     if (q) ans++,ans%=mod;
42     ans=ans*ksm(2,n-m)%mod;
43     ans++,ans%=mod;
44     printf("%d\n",ans);
45     return 0;
46 }

 

posted @ 2015-07-27 16:55  chenyushuo  阅读(175)  评论(0编辑  收藏  举报