General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
125462698 Practice:
lostmen
1140F - 11 C++17 (GCC 9-64) Accepted 1700 ms 175208 KB 2021-08-10 12:15:25 2021-08-10 12:15:25
→ Source
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define int long long
#define pb push_back
#define F first
#define S second
#define m ((l+r)>>1)
#define ls (x<<1)
#define rs (x<<1|1)
using namespace std;
typedef pair<int,int>pii;
const int N=300000,M=600001;
int T,x,y,f[M],sx[M],sy[M];
int ans;
vector<pii>v[M<<2];
map<pii,int>mp;
pii p;
int F(int x){
	while(x!=f[x])x=f[x];
	return x;
}
void Add(int x,int l,int r,int s,int t,pii p){
	if(s<=l&&r<=t){v[x].pb(p);return;}
	if(s<=m)Add(ls,l,m,s,t,p);
	if(m<t)Add(rs,m+1,r,s,t,p);
}
void Solve(int x,int l,int r){
	int pre=ans;
	stack<int>S;
	for(int i=0;i<v[x].size();++i){
		int a=F(v[x][i].F),b=F(v[x][i].S+N);
		if(a==b)continue;
		if(sx[a]+sy[a]>sx[b]+sy[b]){int t=a;a=b,b=t;}
		ans-=sx[a]*sy[a]+sx[b]*sy[b],f[a]=b,sx[b]+=sx[a],sy[b]+=sy[a];
		ans+=sx[b]*sy[b],S.push(a);
	}
	if(l==r)cout<<ans<<' ';
	else Solve(ls,l,m),Solve(rs,m+1,r);
	while(!S.empty()){int t=S.top(),z=f[t];S.pop(),f[t]=t,sx[z]-=sx[t],sy[z]-=sy[t];}
	ans=pre;
}
signed main(){
	cin>>T;
	for(int i=1;i<=T;++i){
		cin>>x>>y;
		p=make_pair(x,y);
		if(mp.count(p))Add(1,1,T,mp[p],i-1,p),mp.erase(p);
		else mp[p]=i;
	}
	for(auto t:mp)Add(1,1,T,t.S,T,t.F);
	for(int i=1;i<=N;++i)sx[f[i]=i]=1;
	for(int i=N+1;i<M;++i)sy[f[i]=i]=1;
	Solve(1,1,T);
	puts("");
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details