BZOJ - 2844 albus就是要第一个出场

已知一个长度为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

           get结论:假设一共n个数,线性基一共cnt个数,那么这n个数一共可以构成2^cnt个数,每个数出现2^(n-cnt)次.

#include<bits/stdc++.h>
using namespace std;
int n, m;
#define ll long long
int d[63];	static const int DEG = 62;
int nu = 0;
void Ins(ll x) {
	for (int i = DEG; i >= 0; i--) {
		if (!(x&(1ll << i)))continue;
		if (!d[i]) { d[i] = x; nu++; break; }
		x ^= d[i];
	}
}int cnt = 0, num[63], id[63];
const int mod = 10086;
int main() {
	int n, q;
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		Ins(a);
	}
	for (int i = 0; i <= 62; i++) {
		if (d[i] > 0)id[cnt++] = i;
	}
	cin >> q;
	ll ans = 0;
	for (int i = 0; i < cnt; i++) {
		if (!(q&(1 << id[i])))continue;
		ans += (1LL << i) % mod;
		ans %= mod;
	}
	for (int i = n - nu; i >= 1; i--)
		ans *= 2, ans %= mod;
	cout << (ans + 1) % mod << "\n";
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值