General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
124439363 Practice:
STARS-sky
1140F - 11 C++17 (GCC 7-32) Accepted 717 ms 84676 KB 2021-07-31 18:51:57 2021-07-31 18:51:56
→ Source
#include<bits/stdc++.h>
#define ls nw<<1
#define rs ls|1
#define mid (l+r>>1)
using namespace std;
const int N=300000,M=N*18+5;
typedef long long LL;
int n,h[N<<2|5],nx[M],to[2][M],cnt,f[N<<1|5],sl[N<<1|5],sr[N<<1|5],top,sx[N|5],sy[N|5];
struct op{int x,y,t;} q[N|5];
bool cmp(op a,op b) {return a.x<b.x||(a.x==b.x&&a.y<b.y)||(a.x==b.x&&a.y==b.y&&a.t<b.t);}
inline int read()
{
	int s=0;char c=getchar();
	while(!isdigit(c))  c=getchar();
	while(isdigit(c))  s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s;
}
void change(int nw,int l,int r,int x,int y,int o)
{
	if(x<=l&&r<=y)  {to[0][++cnt]=q[o].x,to[1][cnt]=q[o].y+300000;nx[cnt]=h[nw];h[nw]=cnt;return;}
	if(x<=mid)  change(ls,l,mid,x,y,o);
	if(y>mid)  change(rs,mid+1,r,x,y,o);
}
int find(int p) {return f[p]==p?p:find(f[p]);}
void dfs(int nw,int l,int r,LL ans)
{
	int ps=0;
	for(int i=h[nw],x,y;i;i=nx[i])
	{
		x=find(to[0][i]),y=find(to[1][i]);
		if(x==y)  continue;
		if(sl[x]+sr[x]<sl[y]+sr[y])  swap(x,y);
		ans+=1ll*sl[x]*sr[y]+1ll*sl[y]*sr[x];
		sx[++top]=x,sy[top]=y,ps++;
		sl[x]+=sl[y],sr[x]+=sr[y];f[y]=x;
	}
	if(l==r)  printf("%lld ",ans);
	else  dfs(ls,l,mid,ans),dfs(rs,mid+1,r,ans);
	while(ps--)  {int x=sx[top],y=sy[top--];sl[x]-=sl[y],sr[x]-=sr[y],f[y]=y;}
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)  q[i].x=read(),q[i].y=read(),q[i].t=i;
	for(int i=1;i<=N<<1;i++)  f[i]=i,sl[i]=i<=N,sr[i]=i>N;
	sort(q+1,q+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		bool out=(q[i].x==1&&q[i].y==1);
		if(q[i].x==q[i+1].x&&q[i].y==q[i+1].y)  change(1,1,n,q[i].t,q[i+1].t-1,i),i++;
		else  change(1,1,n,q[i].t,n,i);
	}dfs(1,1,n,0);return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details