-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathGauss Xor.cpp
50 lines (42 loc) · 810 Bytes
/
Gauss Xor.cpp
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
const int MAXN = (1 << 20);
const int MAXLOG = 64;
struct basis
{
int64_t base[MAXLOG];
void clear()
{
for(int i = MAXLOG - 1; i >= 0; i--)
base[i] = 0;
}
void add(int64_t val)
{
for(int i = MAXLOG - 1; i >= 0; i--)
if((val >> i) & 1)
{
if(!base[i]) { base[i] = val; return; }
else val ^= base[i];
}
}
inline int size()
{
int sz = 0;
for(int i = 0; i < MAXLOG; i++)
sz += (bool)(base[i]);
return sz;
}
int64_t max_xor()
{
int64_t res = 0;
for(int i = MAXLOG - 1; i >= 0; i--)
if(!((res >> i) & 1) && base[i])
res ^= base[i];
return res;
}
bool can_create(int64_t val)
{
for(int i = MAXLOG - 1; i >= 0; i--)
if(((val >> i) & 1) && base[i])
val ^= base[i];
return (val == 0);
}
};