QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#824479#9771. Guessing Gameucup-team5052#RE 284ms45692kbC++172.7kb2024-12-21 14:22:162024-12-21 14:22:24

Judging History

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

  • [2024-12-21 14:22:24]
  • 评测
  • 测评结果:RE
  • 用时:284ms
  • 内存:45692kb
  • [2024-12-21 14:22:16]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
const int N=1e5;
int bad1,bad2,bad3,ffa[200010],U[200010],V[200010],len[200010],minn[20][200010],fa[200010],dfn[200010],idfn[200010],dep[200010],a[1000010],b[1000010],tot;
bool vis[200010],good[200010],bad[200010],del[200010],isroot[200010];
set<pair<int,int>> st2;
vector<int> G[200010];
int getF(int x){return ffa[x]==x?x:ffa[x]=getF(ffa[x]);}
int Low(int u,int v){return dep[u]<dep[v]?u:v;}
int lca(int u,int v)
{
	if(u==v) return u;
	u=dfn[u];v=dfn[v];
	if(u>v) swap(u,v);
	int k=__lg(v-u);
	return fa[Low(minn[k][u+1],minn[k][v-(1<<k)+1])];
}
int dis(int u,int v){return dep[u]+dep[v]-2*dep[lca(u,v)];}
void dfs(int u)
{
	dfn[u]=++tot;minn[0][tot]=u;
	for(int v:G[u])
	{
		if(v==fa[u]) continue;
		fa[v]=u;dep[v]=dep[u]+1;
		dfs(v);
	}
}
void Del(int u)
{
	for(;u && !del[u];u=fa[u])
	{
		del[u]=1;
		(u<=N?bad1:bad2)++;
	}
}
bool badvertex(int x)
{
	if((U[x]<=N)!=(V[x]<=N))
	{
		if(len[x]%4==1) return 1;
		else return 0;
	}
	else
	{
		if(len[x]%4==0) return U[x]>N;
		else return U[x]<=N;
	}
}
void merge(int u,int v)
{
	int x=getF(u),y=getF(v);
	if(x==y)
	{
		if(!bad[x]) (badvertex(x)?bad2:bad1)--;
		bad[x]=1;
		Del(u);Del(v);
		return;
	}
	if(!bad[x] && !bad[y])
	{
		(badvertex(x)?bad2:bad1)--;
		(badvertex(y)?bad2:bad1)--;
		int v1[]={U[x],V[x]},v2[]={U[y],V[y]},p1=U[x],p2=V[x],t,mx=len[x];
		if(mx<len[y]) mx=len[y],p1=U[y],p2=V[y];
		for(int i=0;i<2;i++)
			for(int j=0;j<2;j++)
				if((t=dis(v1[i],v2[j]))>mx)
					mx=t,p1=v1[i],p2=v2[j];
		U[x]=p1;V[x]=p2;len[x]=mx;
		(badvertex(x)?bad2:bad1)++;
	}
	else if(!bad[x]) (badvertex(x)?bad2:bad1)--;
	else if(!bad[y]) (badvertex(y)?bad2:bad1)--;
	else Del(u),Del(v);
	bad[x]=(bad[x] || bad[y]);ffa[y]=x;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int q;
	cin>>q;
	iota(ffa+1,ffa+2*N+1,1);
	for(int i=1;i<=q;i++) cin>>a[i]>>b[i];
	for(int i=1;i<=q;i++)
	{
		if(st2.count({a[i],b[i]})) continue;
		st2.emplace(a[i],b[i]);
		good[i]=1;
		int x=getF(a[i]),y=getF(b[i]+N);
		if(x==y)
		{
			if(!bad[x])
			{
				bad[x]=1;
				isroot[a[i]]=1;
			}
		}
		else if(!bad[y] || !bad[x])
		{
			ffa[y]=x;bad[x]=(bad[x] || bad[y]);
			G[a[i]].push_back(b[i]+N);
			G[b[i]+N].push_back(a[i]);
		}
	}
	for(int i=1;i<=2*N;i++)
		if(!bad[i] && i==ffa[i]) isroot[i]=1;
	for(int i=1;i<=2*N;i++)
		if(!dfn[i] && isroot[i]) dfs(i);
	for(int i=1;i<=17;i++)
		for(int j=1;j+(1<<i)-1<=tot;j++)
			minn[i][j]=Low(minn[i-1][j],minn[i-1][j+(1<<(i-1))]);
	iota(ffa+1,ffa+2*N+1,1);
	for(int i=1;i<=2*N;i++) U[i]=V[i]=i,bad[i]=0;
	bad1=bad2=N;
	for(int i=1;i<=q;i++)
	{
		int u=a[i],v=b[i]+N;
		if(good[i]) merge(u,v);
		cout<<N-bad1<<" "<<N-bad2<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 29520kb

input:

4
1 1
1 2
2 1
2 2

output:

1 0
0 2
1 2
0 0

result:

ok 8 numbers

Test #2:

score: 0
Accepted
time: 284ms
memory: 45692kb

input:

250000
49324 49323
44443 44445
92513 92513
69591 69591
52085 52082
95024 95025
21004 21005
34373 34371
60771 60772
17131 17134
34885 34882
6011 6015
56103 56105
21055 21054
71592 71593
14894 14895
25774 25771
96225 96224
16444 16442
48432 48432
86954 86952
7202 7202
38661 38665
20063 20063
85383 853...

output:

1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
32 0
33 0
34 0
35 0
36 0
37 0
38 0
39 0
40 0
41 0
42 0
43 0
44 0
45 0
46 0
47 0
48 0
49 0
50 0
51 0
52 0
53 0
54 0
55 0
56 0
57 0
58 0
59 0
60 0
61 0
62 0...

result:

ok 500000 numbers

Test #3:

score: -100
Runtime Error

input:

500000
94699 94691
39066 39061
70924 70923
55402 55402
88622 88624
207 205
90609 90603
45892 45892
78872 78873
2321 2323
44788 44785
45517 45515
46316 46315
31599 31594
75478 75473
54876 54872
68947 68941
56371 56375
95794 95791
52971 52975
9094 9095
38174 38174
72230 72221
75527 75523
45981 45984
2...

output:


result: