嘟嘟嘟(洛谷)
这道题算是利用了线性基的一个性质:对于大小为(k)的线性基中亦或出来的一个数(x),那么用原数组的数亦或出来的所有数中,(x)出现了(2 ^ {n - k})次。
那么就可以算出线性基中比(x)小的数有多少个(记为(cnt)),然后答案就是(cnt * 2 ^ {n - k} + 1)。
(其实我现在还不是特别懂)
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
const int maxN = 31;
const ll mod = 10086;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
int p[maxN];
In void insert(int x)
{
for(int i = maxN; i >= 0; --i) if((x >> i) & 1)
{
if(p[i]) x ^= p[i];
else {p[i] = x; return;}
}
}
int b[maxN], cnt = 0;
In ll quickpow(ll a, ll b)
{
ll ret = 1;
for(; b; b >>= 1, a = a * a % mod)
if(b & 1) ret = ret * a % mod;
return ret;
}
int main()
{
n = read(); ll x;
for(int i = 1; i <= n; ++i) x = read(), insert(x);
for(int i = 0; i <= maxN; ++i) if(p[i]) b[cnt++] = i;
x = read();
ll ans = 0;
for(int i = 0; i < cnt; ++i) if((x >> b[i]) & 1) ans += (1 << i);
ans %= mod;
write((ans * quickpow(2, n - cnt) + 1) % mod), enter;
return 0;
}