QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553689 | #6330. XOR Reachable | ucup-team3691# | WA | 550ms | 165572kb | C++20 | 3.0kb | 2024-09-08 18:10:46 | 2024-09-08 18:10:46 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
long long X[1000005];
long long Y[1000005];
long long W[1000005];
pair<long long,long long> xorus[1000005];
vector<pair<long long,long long> >much[4000005];
long long ans=0;
stack<pair<long long,long long> >oper;
long long sz[1000005];
long long sef[1000005];
long long find(long long curr)
{
if(sef[curr]==curr)
{
return curr;
}
return sef[curr];
}
void merge(long long a,long long b)
{
a=find(a);
b=find(b);
if(a!=b)
{
ans=ans-(sz[a]-1)*sz[a];
ans=ans-(sz[b]-1)*sz[b];
if(sz[a]<sz[b])
{
swap(a,b);
}
sz[a]+=sz[b];
ans=ans+(sz[a]-1)*sz[a];
sef[b]=a;
oper.push({a,b});
}
}
void undo()
{
pair<long long,long long>x=oper.top();
oper.pop();
ans-=sz[x.first]*(sz[x.first]-1);
sz[x.first]-=sz[x.second];
sef[x.second]=x.second;
ans+=sz[x.first]*(sz[x.first]-1);
ans+=sz[x.second]*(sz[x.second]-1);
}
long long rasp[1000005];
void dfs(long long node,long long st,long long dr)
{
long long timp=oper.size();
for(auto i:much[node])
{
merge(i.first,i.second);
}
if(st!=dr)
{
long long mij=(st+dr)/2;
dfs(node*2,st,mij);
dfs(node*2+1,mij+1,dr);
}
else
{
rasp[xorus[st].second]=ans/2;
}
while(oper.size()>timp)
{
undo();
}
}
void update(long long node,long long st,long long dr,long long qst,long long qdr,long long nod1,long long nod2)
{
if(xorus[st].first>qdr || xorus[st].first>xorus[dr].first || qst>xorus[dr].first ||qst>qdr)
{
return;
}
if(qst<=xorus[st].first && xorus[dr].first<=qdr)
{
much[node].push_back({nod1,nod2});
return;
}
long long mij=(st+dr)/2;
update(node*2,st,mij,qst,qdr,nod1,nod2);
update(node*2+1,mij+1,dr,qst,qdr,nod1,nod2);
return;
}
void addranges(long long a,long long b,long long w,long long k,long long q)
{
long long pow=1,first,last;
for(long long i=0;i<33;i++)
{
if((k&pow)>=1)
{
first=(k^w);
first=first-first%pow;
first=first^pow;
last=first+pow-1;
update(1,1,q,first,last,a,b);
}
pow=pow*2;
}
}
signed main()
{
long long n,i,j,k,l,t,op,a,b,x,m,w,q;
cin>>n>>m>>k;
for(i=1;i<=m;i++)
{
cin>>a>>b>>w;
X[i]=a;
Y[i]=b;
W[i]=w;
}
cin>>q;
for(i=1;i<=n;i++)
{
sz[i]=1;
sef[i]=i;
}
for(i=1;i<=q;i++)
{
cin>>xorus[i].first;
xorus[i].second=i;
}
sort(xorus+1,xorus+q+1);
for(i=1;i<=m;i++)
{
addranges(X[i],Y[i],W[i],k,q);
}
dfs(1,1,q);
for(i=1;i<=q;i++)
{
cout<<rasp[i]<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 17868kb
input:
4 5 5 1 2 17 1 3 4 2 3 20 2 4 3 3 4 5 4 0 7 16 167
output:
2 6 3 0
result:
ok 4 number(s): "2 6 3 0"
Test #2:
score: 0
Accepted
time: 8ms
memory: 17912kb
input:
9 13 488888932 2 7 771479959 3 8 783850182 5 7 430673756 6 8 350738034 4 9 400768807 2 3 83653266 1 2 829786563 5 8 357613791 7 9 579696618 3 7 423191200 3 5 867380255 1 9 907715012 6 9 1033650694 8 498260055 144262908 117665696 848664012 983408133 32610599 478007408 134182829
output:
16 7 5 13 13 16 16 5
result:
ok 8 numbers
Test #3:
score: -100
Wrong Answer
time: 550ms
memory: 165572kb
input:
446 99235 764320136 1 2 467639025 1 39 240791819 1 197 320023434 1 391 968343602 1 116 841220144 1 345 697806443 1 409 489643820 1 339 733516272 1 89 560099922 1 431 722346703 1 433 246809211 1 344 769002876 1 234 597076758 1 178 505730391 1 75 826728597 1 74 14756981 1 63 280238017 1 288 638627144 ...
output:
469119197378 465233397038 464539139198 469526108918 99235 472554402758 312188375445 99235 99235 99235 99235 99235 99235 99235 471330266138 99235 99235 99235 466333698818 469409830478 464596974218 99235 99235 99235 99235 99235 99235 99235 468480121358 469467967898 463787611538 99235 465349157078 9923...
result:
wrong answer 1st numbers differ - expected: '99235', found: '469119197378'