QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307466 | #6795. Everyone Loves Playing Games | chengch | AC ✓ | 39ms | 3672kb | C++20 | 1.4kb | 2024-01-18 17:06:10 | 2024-01-18 17:06:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct basis {
ll p[100];
void clear() { memset(p, 0, sizeof p); }
void insert(ll x) {
for (int i = 60; i >= 0; i--) {
if (x >> i & 1) {
if (p[i]) x ^= p[i];
else {
p[i] = x;
break;
}
}
}
}
ll query_max(ll x) {
for (int i = 60; i >= 0; i--)
if (!(x >> i & 1)) x ^= p[i];
return x;
}
ll query_min(ll x) {
for (int i = 60; i >= 0; i--)
if (x >> i & 1) x ^= p[i];
return x;
}
} L;
int T, n, m;
ll a[10010];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll x, y;
scanf("%lld%lld", &x, &y);
ans ^= x;
a[i] = x ^ y;
}
L.clear();
for (int i = 1; i <= m; i++) {
ll x, y;
scanf("%lld%lld", &x, &y);
ans ^= x;
L.insert(x ^ y);
}
ans = L.query_min(ans);
for (int i = 1; i <= n; i++) {
a[i] = L.query_min(a[i]);
}
L.clear();
for (int i = 1; i <= n; i++) L.insert(a[i]);
cout << L.query_max(ans) << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
2 1 1 6 3 4 1 2 2 1 3 4 6 5 4 2 2
output:
2 2
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 39ms
memory: 3672kb
input:
15 10000 19 393592642880030158 136857754781138651 64253273480262588 14313422237514072 307460297920437500 243820607396725 21817935197991240 483662625803120946 101295580681553439 176530315178675718 299210522568785323 76213955574929634 71280408782239858 46474979272278520 355918902735266055 227582800425...
output:
2199023255551 5910974510923775 17179869183 1008806316530991103 855638015 2424831 163208757247 12884901887 12582911 17179869183 402595213 2199023255549 10485759 983039 2265548478697
result:
ok 15 lines