QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#884144 | #10067. Cheese | guleng2007# | 0 | 454ms | 138016kb | C++20 | 1.3kb | 2025-02-05 21:35:21 | 2025-02-05 21:35:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int LG2[(1<<16)+5], n;
struct BCJ
{
long long fa[N], val[N], Base;
void init()
{
for(int i=1;i<=n;i++)
fa[i]=i, val[i]=0;
}
int getfa(int x)
{
if(x!=fa[x])
{
fa[x]=getfa(fa[x]);
(val[x] += val[fa[x]]) %= Base;
}
return fa[x];
}
bool check(int x,int y,int z)
{
z=(z%Base+Base)%Base;
int fax=getfa(x), fay=getfa(y);
if(fax==fay)
{
if((val[x]-val[y]+Base)%Base!=z)
return false;
return true;
}
return true;
}
void merge(int x,int y,int z)
{
z=(z%Base+Base)%Base;
int fax=getfa(x), fay=getfa(y);
if(fax!=fay)
{
fa[fax]=fay;
val[fax]=(val[y]-val[x]+z+Base)%Base;
}
}
} U[20];
int main()
{
int m;
cin >> n >> m;
for(int i=0;i<=16;i++)
U[i].Base=1<<i;
U[16].Base=1e18;
for(int i=0;i<=16;i++)
U[i].init(), LG2[1<<i]=i;
for(int i=1;i<=m;i++)
{
int x,y,z,v,typ;
scanf("%d %d %d %d",&x,&y,&z,&v);
if(v==-1)
typ=16;
else
typ=LG2[v];
bool can=true;
for(int i=1;i<=typ;i++)
if(!U[i].check(x,y,z))
{
can=false;
break;
}
printf("%d\n",can);
if(can)
{
for(int i=1;i<=typ;i++)
U[i].merge(x,y,z);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 73448kb
input:
10 10 5 3 0 4 6 8 1 4 9 2 0 128 7 8 6 4096 9 6 7 256 2 5 1 8 10 6 7 128 9 1 9 32 9 3 2 2 9 3 1 256
output:
1 1 1 1 1 1 1 1 0 0
result:
wrong answer 10th lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 8
Accepted
time: 0ms
memory: 73560kb
input:
2 3 2 1 1 2 2 1 1 2 2 1 9 2
output:
1 1 1
result:
ok 3 lines
Test #8:
score: 8
Accepted
time: 1ms
memory: 73580kb
input:
2 10 1 2 0 2 1 2 93 2 1 2 93 2 1 2 0 2 1 2 5 2 1 2 29 2 1 2 19 2 1 2 0 2 1 2 23 2 1 2 0 2
output:
1 0 0 1 0 0 0 1 0 1
result:
ok 10 lines
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 73576kb
input:
10 10 8 10 0 2 7 2 1 2 1 6 1 2 1 6 1 2 10 4 0 2 8 5 1 2 5 2 0 2 7 8 0 2 7 10 12234 2 1 4 0 2
output:
1 1 1 1 1 1 1 0 0 1
result:
wrong answer 8th lines differ - expected: '1', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 1ms
memory: 75472kb
input:
10 100 7 3 27490 -1 4 3 12572 -1 10 2 26036 -1 7 1 21174 -1 7 10 576 -1 4 3 12572 -1 7 6 798 -1 6 8 20930 -1 7 8 14464 -1 6 4 20671 -1 4 3 12572 -1 4 2 11764 -1 1 3 6316 -1 1 8 16743 -1 9 3 6305 -1 10 9 20609 -1 1 8 554 -1 6 4 13117 -1 1 8 20767 -1 7 6 798 -1 10 6 222 -1 4 3 12572 -1 5 4 11211 -1 7 ...
output:
1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
result:
wrong answer 6th lines differ - expected: '1', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 0ms
memory: 73448kb
input:
10 10 4 9 5 8 10 7 4894 8192 4 3 10 32 4 5 14 32 5 3 6972 32768 2 5 173 1024 4 5 1134 -1 6 9 22 64 8 3 307 512 1 5 16 64
output:
1 1 1 1 0 1 0 1 1 1
result:
wrong answer 5th lines differ - expected: '1', found: '0'
Subtask #5:
score: 0
Wrong Answer
Test #27:
score: 0
Wrong Answer
time: 0ms
memory: 75472kb
input:
3 500 1 2 12 32 1 3 7 32 1 3 6 32 1 2 40 2 3 2 69 32 3 2 5 16 1 3 7 16 1 2 4 8 3 2 5 16 1 2 13 4 1 2 0 4 3 2 5 32 1 2 12 16 1 2 12 32 1 3 99 2 3 2 5 32 1 2 4 8 1 2 60 32 1 2 12 32 1 3 40 4 1 2 4 8 1 2 4 8 3 2 5 32 1 3 91 4 1 3 96 2 1 3 3 4 3 2 5 8 1 2 11 32 3 2 1 2 3 2 61 32 1 3 7 8 1 2 76 16 1 3 22...
output:
1 1 0 0 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 ...
result:
wrong answer 4th lines differ - expected: '1', found: '0'
Subtask #6:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 454ms
memory: 138016kb
input:
500000 500000 14167 287469 6 512 104859 279213 2 2048 230903 352549 2 16384 20412 206001 2 64 31177 491167 4 16384 374670 2710 7 1024 463688 378992 3 2048 239144 207425 4 16384 407488 243971 0 2 278719 34617 9 256 155441 483962 1 16 263008 53859 0 8192 397627 240244 4 8 387592 488780 2 16384 224109 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 242024th lines differ - expected: '1', found: '0'