bzoj2884 albus就是要第一个出场

Description

已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2^S定义为S 所有子集构成的集合。定义映射 f : 2^S -> Zf(空集) = 0f(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
样例解释:
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

正解:线性基。

题意就很绕。。给定一个序列,任意异或得到一个新的序列,并把序列排序。再给定一个Q,求Q在新序列中的排名。

然后我就不会做了。看了题解才知道线性基原来还有一个神奇的性质。

n个数的序列共有$2^{n}$种异或和,n个数的线性基共有k个数,所以n个数的线性基共有$2^{k}$种不同的异或和。神奇的是,$2^{k}$不同的异或和在$2^{n}$种异或和中出现的次数竟然相同,都是$2^{n-k}$次!

所以,我们只要算出线性基中异或和小于Q的数的个数,然后乘上$2^{n-k}$,再加上1,这个就是答案了。

 //It is made by wfj_2048~
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define inf (1<<30)
#define rhl (10086)
#define N (100010)
#define il inline
#define RG register
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) using namespace std; vector <int> Q; int a[N],p[],n,q,rk,cnt; il int gi(){
RG int x=,q=; RG char ch=getchar(); while ((ch<'' || ch>'') && ch!='-') ch=getchar();
if (ch=='-') q=-,ch=getchar(); while (ch>='' && ch<='') x=x*+ch-,ch=getchar(); return q*x;
} il void insert(RG int x){
for (RG int i=;i>=;--i)
if (x&(<<i)){
if (!p[i]){ p[i]=x; break; }
x^=p[i];
}
return;
} il int qpow(RG int a,RG int b){
RG int ans=;
while (b){
if (b&) ans=ans*a%rhl;
a=a*a%rhl,b>>=;
}
return ans;
} il void work(){
n=gi(); for (RG int i=;i<=n;++i) a[i]=gi(),insert(a[i]); q=gi();
for (RG int i=;i<=;++i) if (p[i]) Q.push_back(i),cnt++;
for (RG int i=;i<Q.size();++i) if (q&(<<Q[i])) rk+=<<i;
printf("%d\n",(rk%rhl*qpow(,n-cnt)%rhl+)%rhl);
return;
} int main(){
File("albus");
work();
return ;
}
上一篇:雷林鹏分享:jQuery EasyUI 树形菜单 - 创建基础树形网格


下一篇:java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱