General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
147271896 Practice:
guozexin
1140F - 11 C++14 (GCC 6-32) Accepted 748 ms 99344 KB 2022-02-22 16:28:16 2022-02-22 16:28:16
→ Source
#include<bits/stdc++.h>
#define pii pair<int,int>
#define m_p make_pair
using namespace std;
const int N=6e5+10;
const int M=3e5;
int n,fa[N],L[N],R[N],dep[N],now=0;
map<pii,int> mp;
vector<pii> q[N*4];
long long ans=0;
struct node{int x,add;long long ans;}s[N]; 
int get(int x)
{
	while(x!=fa[x]) x=fa[x];
	return fa[x]; 
}
void merge(int x,int y)
{
	int fx=get(x),fy=get(y);
	if(fx==fy) return;
	if(dep[fx]>dep[fy]) swap(fx,fy);
	s[++now]=(node){fx,dep[fx]==dep[fy],ans};
	ans-=1ll*L[fx]*R[fx]+1ll*L[fy]*R[fy];
	fa[fx]=fy,L[fy]+=L[fx],R[fy]+=R[fx];
	if(dep[fx]==dep[fy]) dep[fy]++;
	ans+=1ll*L[fy]*R[fy];
}

void change(int p,int l,int r,int L,int R,pii x)
{
	if(L<=l&&r<=R){q[p].push_back(x);return;}
	int mid=(l+r)>>1;
	if(L<=mid) change(p<<1,l,mid,L,R,x);
	if(mid<R) change(p<<1|1,mid+1,r,L,R,x);
}

void solve(int p,int l,int r)
{
	int lst=now;
	for(int i=0;i<q[p].size();i++) merge(q[p][i].first,q[p][i].second);
	if(l==r) printf("%lld ",ans);
	else
	{
		int mid=(l+r)>>1;
		solve(p<<1,l,mid),solve(p<<1|1,mid+1,r);
	}
	while(now>lst)
	{
		int x=s[now].x;
		L[fa[x]]-=L[x],R[fa[x]]-=R[x],dep[fa[x]]-=s[now].add;
		fa[x]=x;
		ans=s[now].ans;
		now--;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;i++)
	{
		scanf("%d%d",&x,&y);y+=M;
		pii a=m_p(x,y);
		if(!mp[a]) mp[a]=i;
		else change(1,1,n,mp[a],i-1,a),mp.erase(a);
	}
	for(int i=1;i<=M;i++) fa[i]=i,L[i]=1,dep[i]=1;
	for(int i=M+1;i<=2*M;i++) fa[i]=i,R[i]=1,dep[i]=1;
	for(map<pii,int>:: iterator it=mp.begin();it!=mp.end();it++) change(1,1,n,(*it).second,n,(*it).first);
	solve(1,1,n); 
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details