-
Notifications
You must be signed in to change notification settings - Fork 2
/
Xor Basis
126 lines (106 loc) · 2.56 KB
/
Xor Basis
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/// prac prob :
https://atcoder.jp/contests/abc141/tasks/abc141_f
https://atcoder.jp/contests/agc045/tasks/agc045_a
https://atcoder.jp/contests/abc236/tasks/abc236_f
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
#define MP make_pair
#define pb push_back
#define EB emplace_back
#define nn '\n'
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define UNIQUE(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end()))) ;
#define all(vec) vec.begin(),vec.end()
#define int long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define ff first
#define ss second
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std ;
typedef long long LL ;
const int MOD=998244353,Base=998244353 ;
const int N=1e6+7 ;
const int oo=1LL*1000*1000*1000*1000*1000*1000+7LL ;
const double pie=acos(-1.0) ;
const double EPS=1e-9 ;
using i64 = long long;
int a[N] , n ;
/// basis for max query ...
struct Basis {
i64 a[64];
bool insert(i64 x) {
for (int i = 60; ~i; i--)
if (x >> i & 1)
if (a[i]) x ^= a[i];
else return a[i] = x, true;
return false;
}
i64 ask() {
i64 res = 0;
for (int i = 60; ~i; i--)
res = max(res, res ^ a[i]);
return res;
}
void init() {
memset(a, 0, sizeof a);
}
} b;
int32_t main()
{
IOS
cin>>n ;
int x = 0 ;
for(int i=1;i<=n;i++){
cin>>a[i] ; x^=a[i] ;
b.insert(a[i]) ;
}
cout<<b.ask()<<endl ;
return 0 ;
}
/// check whether we can reduce or not ...
struct Basis
{
vector<int> basis;
int reduce(int x)
{
for (auto b : basis) if ((x ^ b) < x) x ^= b;
return x;
}
void insert(int x)
{
int r = reduce(x);
if (r) basis.pb(r);
}
};
int32_t main()
{
IOS
int test ;
cin>>test ;
while(test--)
{
cin>>n ;
Basis b ;
for(int i=0; i<n; i++)
{
cin>>a[i] ;
}
string s ;
cin>>s ; bool f = 0 ;
for(int i=n-1; i>=0; i--)
{
if(s[i]=='0')
b.insert(a[i]) ;
else if(b.reduce(a[i]))
f=1 ;
}
cout<<f<<endl ;
}
return 0 ;
}