QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153083 | #6795. Everyone Loves Playing Games | LFCode | AC ✓ | 30ms | 1496kb | C++14 | 1.2kb | 2023-08-29 11:02:28 | 2023-08-29 11:02:28 |
Judging History
answer
#include<cstdio>
#define int long long
const int N=60;
struct LinearBasis{
int a[N];
bool clear(){for(int i=59;i+1;i--)a[i]=0;return true;}
bool push(int x){
for(int i=59;i+1;i--){
if(!((x>>i)&1))continue;
if(a[i]){x^=a[i];continue;}
for(int j=0;j<i;j++)x^=a[j];
for(int j=59;j>i;j--)if((a[j]>>i)&1)a[j]^=x;
a[i]=x;return true;
}
return false;
}
int &operator [](int x){return a[x];}
int qmin(int x){
for(int i=59;i+1;i--)if((x>>i)&1)x^=a[i];
return x;
}
int qmax(int x){
for(int i=59;i+1;i--)if(!((x>>i)&1))x^=a[i];
return x;
}
};
LinearBasis A,B,C;
int read(){
char ch=getchar();int nn=0,ssss=1;
while(ch<'0'||ch>'9'){if(ch=='-')ssss*=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){nn=nn*10+(ch-'0');ch=getchar();}
return nn*ssss;
}
bool solve(){
int n=read();int m=read();int x=0;
A.clear();B.clear();C.clear();
for(int i=1;i<=n;i++){
int a=read();int b=read();
x^=a;A.push(a^b);
}
for(int i=1;i<=m;i++){
int a=read();int b=read();
x^=a;B.push(a^b);
}
for(int i=59;i+1;i--)if(A[i])C.push(B.qmin(A[i]));
printf("%lld\n",C.qmax(B.qmin(x)));
return true;
}
signed main(){
int T=read();
while(T--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1484kb
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: 30ms
memory: 1496kb
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