Language: C++

#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#define LL long long
#define N (100005)
using namespace std;
int n,m,t,cnt;
LL tot,ans[N];
int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
template <typename T> void read(T&t) {
	t=0;
	bool fl=true;
	char p=getchar();
	while (!isdigit(p)) {
		if (p=='-') fl=false;
		p=getchar();
	}
	do {
		(t*=10)+=p-48;p=getchar();
	}while (isdigit(p));
	if (!fl) t=-t;
}
int ask(int x){
	if (fa[x]==x) return x;
	fa[x]=ask(fa[x]);
	return fa[x];
}
inline void build(int &u,int l,int r,int op){
	u=++cnt;
	size[u]=1;
	if (l==r) return;
	int mid=l+r>>1;
	if (op<=mid) build(lson[u],l,mid,op);
	else build(rson[u],mid+1,r,op);
}
inline merge(int x,int y){
	if (!x||!y) return x|y;
	tot+=1ll*size[lson[x]]*size[rson[y]]+1ll*size[rson[x]]*size[lson[y]];
	lson[x]=merge(lson[x],lson[y]);
	rson[x]=merge(rson[x],rson[y]);
	size[x]=size[lson[x]]+size[rson[x]];
	return x;
}
int main(){
	read(n),read(m);
	for (int i=1;i<=m;i++){
		read(x[i]),read(y[i]);
	}
	for (int i=1;i<=n;i++) fa[i]=i,build(root[i],1,n,i);
	ans[m]=n*(n-1)/2;
	for (int i=m;i>=1;i--){
		ans[i-1]=ans[i];
		int fx=ask(x[i]),fy=ask(y[i]);
		if (fx==fy) continue;
		tot=0;
		root[fx]=merge(root[fx],root[fy]);
		fa[fy]=fx;
		ans[i-1]-=tot;
	}
	for (int i=1;i<=m;i++) printf("%lld\n",ans[i]);
	return 0;
}


Compiler output:
a.cc: In function 'void build(int&, int, int, int)':
a.cc:34:9: error: reference to 'size' is ambiguous
   34 |         size[u]=1;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:5:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc: At global scope:
a.cc:40:8: error: ISO C++ forbids declaration of 'merge' with no type [-fpermissive]
   40 | inline merge(int x,int y){
      |        ^~~~~
a.cc: In function 'int merge(int, int)':
a.cc:42:18: error: reference to 'size' is ambiguous
   42 |         tot+=1ll*size[lson[x]]*size[rson[y]]+1ll*size[rson[x]]*size[lson[y]];
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:42:32: error: reference to 'size' is ambiguous
   42 |         tot+=1ll*size[lson[x]]*size[rson[y]]+1ll*size[rson[x]]*size[lson[y]];
      |                                ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:42:50: error: reference to 'size' is ambiguous
   42 |         tot+=1ll*size[lson[x]]*size[rson[y]]+1ll*size[rson[x]]*size[lson[y]];
      |                                                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:42:64: error: reference to 'size' is ambiguous
   42 |         tot+=1ll*size[lson[x]]*size[rson[y]]+1ll*size[rson[x]]*size[lson[y]];
      |                                                                ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:45:9: error: reference to 'size' is ambiguous
   45 |         size[x]=size[lson[x]]+size[rson[x]];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:45:17: error: reference to 'size' is ambiguous
   45 |         size[x]=size[lson[x]]+size[rson[x]];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~
a.cc:45:31: error: reference to 'size' is ambiguous
   45 |         size[x]=size[lson[x]]+size[rson[x]];
      |                               ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:13:51: note:                 'int size [5000250]'
   13 | int x[N],y[N],fa[N],root[N],lson[N*50],rson[N*50],size[N*50];
      |                                                   ^~~~