General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
128684091 Practice:
lijunhan
1140F - 11 C++14 (GCC 6-32) Accepted 826 ms 83016 KB 2021-09-13 03:52:21 2021-09-13 03:52:22
→ Source
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
map<pair<int,int>,int>mp;
vector<pair<int,int> >ve[maxn<<2];ll ans;
void ins(int k,int l,int r,int L,int R,pair<int,int>v) {
	if(l>R||L>r) return;
	if(L<=l&&r<=R) return ve[k].push_back(v);int mid=l+r>>1;
	ins(k<<1,l,mid,L,R,v),ins(k<<1|1,mid+1,r,L,R,v);
}
struct che {int x,y,fy;}c[maxn];int f[maxn<<1],sz[maxn<<1],top,X[maxn<<1],Y[maxn<<1],q;
int GF(int x) {while(x^f[x]) x=f[x];return x;}
void mrg(int x,int y) {
	if((x=GF(x))==(y=GF(y))) return;
	if(sz[x]<sz[y]) swap(x,y);
	c[++top]=(che){x,y,f[y]};
	ans-=1ll*X[x]*Y[x]+1ll*X[y]*Y[y];
	f[y]=x,sz[x]+=sz[y],X[x]+=X[y],Y[x]+=Y[y];
	ans+=1ll*X[x]*Y[x];
}
void udo(int tp) {
	int x,y;while(top>tp) {
		x=c[top].x,y=c[top].y,ans-=1ll*X[x]*Y[x];
		f[y]=c[top].fy,sz[x]-=sz[y],X[x]-=X[y],Y[x]-=Y[y];
		ans+=1ll*X[x]*Y[x]+1ll*X[y]*Y[y],--top;
	}
}
void byd(int k,int l,int r) {
	int tp=top;for(auto y:ve[k]) mrg(y.first,3e5+y.second);
	if(l==r) cout<<ans<<' ';
	else byd(k<<1,l,(l+r>>1)),byd(k<<1|1,((l+r)>>1)+1,r);udo(tp);
}
signed main() {
	ios::sync_with_stdio(0),cin.tie(0);
	for(int i=1;i<=3e5;i++) f[i]=i,X[i]=sz[i]=1;
	for(int i=3e5+1;i<=6e5;i++) f[i]=i,Y[i]=sz[i]=1;
	cin>>q;for(int i=1,x,y;i<=q;i++) {
		cin>>x>>y;
		if(mp[make_pair(x,y)]) ins(1,1,q,mp[make_pair(x,y)],i-1,make_pair(x,y)),mp.erase(make_pair(x,y));
		else mp[make_pair(x,y)]=i;
	}
	for(auto y:mp) ins(1,1,q,y.second,q,y.first);
	byd(1,1,q);
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details