Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

CF959F Mahmoud and Ehab and yet another xor task

LuoGu: CF959F Mahmoud and Ehab and yet another xor task

F. Mahmoud and Ehab and yet another xor task

线性基的性质:能表示出所有原来集合能表示的异或和,线性基内的任意子集表示的异或和不同,任意数表示方案只有一种。

对于一个数 $k$ ,如果线性基不能表示出来,那么原集合一定不能表示;如果线性基能表示出来,那么原集合任意选择一些数,一定能表示出来。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <cstdio>
#include <algorithm>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write(Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar(x % 10 + '0');
}
const int N = 1e5 + 10, M = 20, mod = 1e9 + 7;
struct Query
{
int t, k, id;
bool operator < (const Query &_) const
{
return t < _.t;
}
} q[N];
int cnt, v[M];
int n, m, w[N], p[N], ans[N];
void insert (int x)
{
for (int i = M - 1; ~i; i--)
if (x >> i & 1)
{
if (!v[i])
return v[i] = x, cnt++, void();
x ^= v[i];
}
}
bool check (int x)
{
for (int i = M - 1; ~i; i--)
if (x >> i & 1)
{
if (!v[i])
return false;
x ^= v[i];
}
return true;
}
int main ()
{
read(n), read(m);
for (int i = 1; i <= n; i++)
read(w[i]);
for (int i = 0; i < m; i++)
{
read(q[i].t), read(q[i].k);
q[i].id = i;
}
sort(q, q + m);
p[0] = 1;
for (int i = 1; i <= n; i++)
p[i] = p[i - 1] * 2 % mod;
for (int i = 0, t = 0; i < m; i++)
{
while (t < q[i].t)
insert(w[++t]);
ans[q[i].id] = check(q[i].k) ? p[t - cnt] : 0;
}
for (int i = 0; i < m; i++)
write(ans[i]), puts("");
return 0;
}