【BZOJ 2844】 albus就是要第一个出场

来源:互联网 发布:mysql的级联删除 编辑:程序博客网 时间:2024/05/21 22:06

2844: albus就是要第一个出场

Time Limit: 6 Sec  Memory Limit: 128 MB
Submit: 436  Solved: 190
[Submit][Status]

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


Source

湖北省队互测


高斯消元。


详见点击打开链接。


由于本题不去重,所以要乘每个结果出现的次数(注意本题还有空集的情况!)


#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cmath>#define mod 10086#define LL long longusing namespace std;int now,n,a[100005],q;void Gauss(){now=1;int m=31;while (m--){for (int i=now;i<=n;i++)if (a[i]&(1<<m)){swap(a[i],a[now]);for (int j=1;j<=n;j++){if (j!=now&&(a[j]&(1<<m))) a[j]^=a[now];}now++;break;}}now--;}int main(){        scanf("%d",&n);for (int i=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&q);Gauss();int x=0;LL rk=0;        for (int i=1;i<=now;i++){if ((x^a[i])>q) continue;x^=a[i];rk=(rk+(LL)(1LL<<(now-i)))%(LL)mod;}for (int i=1;i<=n-now;i++)rk<<=1LL,rk%=(LL)mod;rk++;rk%=(LL)mod;printf("%lld\n",rk);return 0;}



感悟:

1.在高斯消元完之后存在x个0,那么每个数就会出现2^x次

2 0
原创粉丝点击