QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#926137 | #6795. Everyone Loves Playing Games | zjjws | AC ✓ | 20ms | 3840kb | C++20 | 2.4kb | 2025-03-05 16:14:18 | 2025-03-05 16:14:18 |
Judging History
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#include <string>
const int Rea=1e5+3;
bool ifnum(char x){return x>='0'&&x<='9';}
bool ifupchr(char x){return x>='A'&&x<='Z';}
bool iflochr(char x){return x>='a'&&x<='z';}
bool ifchr(char x){return ifnum(x)||ifupchr(x)||iflochr(x);}
struct Rin
{
char c;
char gc()
{
static char rea[Rea];
static char *head,*tail;
return head==tail&&(tail=(head=rea)+fread(rea,1,Rea,stdin)
,head==tail)?EOF:*head++;
}
Rin&operator >>(int &x)
{
bool tag=false;x=0;
for(c=gc();!ifnum(c);c=gc())if(c=='-'){c=gc();tag=true;break;}
for(;ifnum(c);c=gc())x=(x<<1)+(x<<3)+(c^'0');if(tag)x=-x;return *this;
}
Rin&operator >>(LL &x)
{
bool tag=false;x=0;
for(c=gc();!ifnum(c);c=gc())if(c=='-'){c=gc();tag=true;break;}
for(;ifnum(c);c=gc())x=(x<<1)+(x<<3)+(c^'0');if(tag)x=-x;return *this;
}
Rin&operator >>(char &x)
{
for(c=gc();!ifchr(c);c=gc());
x=c;
return *this;
}
Rin&operator >>(string &x)
{
x.clear();
for(c=gc();!ifchr(c);c=gc());
for(;ifchr(c);c=gc())x.push_back(c);
return *this;
}
}rin;
const int N=1e4+3;
int n,m;
LL val;
LL a[65];
LL b[65];
void clear()
{
val=0;
for(int i=0;i<62;i++)a[i]=b[i]=0;
return;
}
void insert(LL v,LL *f)
{
for(int i=61;i>=0;i--)if((v>>i)&1)
{
if(f[i]>0)v^=f[i];
else {f[i]=v;break;}
}
return;
}
void work()
{
rin>>n>>m;
clear();
for(int i=1;i<=n;i++)
{
LL x,y;rin>>x>>y;
val^=x;
insert(x^y,a);
}
for(int i=1;i<=m;i++)
{
LL x,y;rin>>x>>y;
val^=x;
insert(x^y,b);
}
for(int i=61;i>=0;i--)
{
if(a[i]>0||b[i]>0)
{
if(a[i]>0&&b[i]>0)
{
if((val>>i)&1)
{
val^=a[i];
insert(a[i]^b[i],a);
}
else insert(a[i]^b[i],a);
}
else
{
if(a[i]>0&&!((val>>i)&1))val^=a[i];
else if(b[i]>0&&((val>>i)&1))val^=b[i];
}
}
}
printf("%lld\n",val);
}
int main()
{
int T;rin>>T;
for(;T-->0;)work();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 20ms
memory: 3840kb
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