QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#98658#6330. XOR ReachableWolamWA 269ms149324kbC++142.2kb2023-04-19 17:14:422023-04-19 17:14:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-19 17:14:47]
  • 评测
  • 测评结果:WA
  • 用时:269ms
  • 内存:149324kb
  • [2023-04-19 17:14:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int q,n,m,k,u[100005],v[100005],w[100005];
int ch[3000005][2];
int L[300005],R[300005];
int tot=1;
vector<int> tree[400005];
int fa[100005],sz[100005],ans,d[100005],b[100005];
int op[100005];
int find(int x)
{
	if(x==fa[x])return x;
	return find(fa[x]);
}
bool cmp(int u,int v)
{
	return d[u]<d[v];
}
void ins(int x,int num)
{
	int p=1;
	for(int i=29;i>=0;i--)
	{
		int t=(x>>i)&1;
		if(!ch[p][t])
		{
			ch[p][t]=++tot;
			L[tot]=R[tot]=num;
		}
		p=ch[p][t];
		L[p]=min(L[p],num);
		R[p]=max(R[p],num);
	}
}
void update(int l,int r,int k,int x,int y,int v)
{
	if(!x||!y)return;
	if(x>r||y<l)return;
	if(x<=l&&r<=y)
	{
//		cerr<<l<<" "<<r<<" "<<v<<endl;
		tree[k].push_back(v);
		return;
	}
	int mid=(l+r)>>1;
	update(l,mid,k<<1,x,y,v);
	update(mid+1,r,k<<1|1,x,y,v);
}
void upd(int w,int num)
{
	int p=1;
	for(int i=29;i>=0;i--)
	{
		if(!p)return;
		int t=(w>>i)&1,x=(k>>i)&1;
		if(x)
		{
			update(1,q,1,L[ch[p][t]],R[ch[p][t]],num);
		//	cerr<<i<<" "<<L[ch[p][t]]<<" "<<R[ch[p][t]]<<" "<<num<<endl;
		}
		p=ch[p][t^x];
	}
}
int s[3000005][2],ls;
void merge(int x,int y)
{
	x=find(x),y=find(y);
	if(x==y)return;
	if(sz[x]>sz[y])swap(x,y);
	++ls;
	s[ls][0]=x;
	s[ls][1]=y;
	fa[x]=y;
	ans+=sz[x]*sz[y];
	sz[y]+=sz[x];
}
void redo(int x,int y)
{
	sz[y]-=sz[x];
	ans-=sz[x]*sz[y];
	fa[x]=x;
	ls--;
}
void dfs(int l,int r,int k)
{
	int now=ls;
	for(auto it: tree[k])
	{
		//cerr<<l<<" "<<r<<" "<<it<<endl;
		merge(u[it],v[it]);
	}
	if(l==r)
		op[b[l]]=ans;
	if(l!=r)
	{
		int mid=(l+r)>>1;
		dfs(l,mid,k<<1);
		dfs(mid+1,r,k<<1|1);
	}
	while(ls>now)
		redo(s[ls][0],s[ls][1]);
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i]>>w[i];
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>d[i];
		b[i]=i;
	}
	sort(b+1,b+q+1,cmp);
	for(int i=1;i<=q;i++)
	{
		ins(d[b[i]],i);
	}
	//cerr<<1<<endl;
	for(int i=1;i<=m;i++)
	{
		upd(w[i],i);
	}
	//cerr<<1<<endl;
	dfs(1,q,1);
	for(int i=1;i<=q;i++)
		cout<<op[i]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 21980kb

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: 1ms
memory: 21780kb

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: 269ms
memory: 149324kb

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:

99235
99235
99235
99235
99235
99235
99235
99235
0
99235
0
0
0
0
99235
0
99235
99235
99235
99235
99235
99235
99235
99235
0
99235
0
0
99235
99235
99235
0
99235
0
0
99235
99235
99235
99235
99235
99235
99235
99235
99235
0
99235
99235
99235
99235
99235
0
99235
99235
99235
99235
0
99235
99235
99235
0
0
99...

result:

wrong answer 9th numbers differ - expected: '99235', found: '0'