Blog of RuSun

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

线性基模板

用于求解线性代数问题。

以异或为例。

更一般的,在实数上的应用见其他题目。

查看代码
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
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 60;
typedef long long LL;
int n;
LL c[N];
void insert(LL x)
{
for (int i = 50; ~i; i--)
if (x >> i & 1)
{
if (!c[i])
{
c[i] = x;
return;
}
x ^= c[i];
}
}
LL query()
{
LL res = 0;
for (int i = 50; ~i; i--)
res = max(res, res ^ c[i]);
return res;
}
int main()
{
scanf("%d", &n);
for (LL a; n; n--)
{
scanf("%lld", &a);
insert(a);
}
printf("%lld", query());
return 0;
}