Language: C++

#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 100001
ll visit[maxn],sz[maxn],cnt=0;
void init()
{
    for(int i=0;i<maxn;i++)
    {
        visit[i]=i;
        sz[i]=1;
    }
}
ll find(ll x)
{
    if(visit[x]!=x)
    {
        return visit[x]=find(visit[x]);
    }
    return x;
}
void Union(ll x,ll y)
{
    ll val=find(x),val1=find(y);
    if(val==val1)
    {
        return;
    }
    cnt-=sz[val]*sz[val];
    cnt-=sz[val1]*sz[val1];
    sz[val1]+=sz[val];
    cnt+=sz[val1]*sz[val1];
    visit[val]=val1;
}
int main()
{   
    fastIO;
    init();
    ll n,m;
    cin>>n>>m;
    pair<ll,ll>p[m];
    ll x,y,val,val1;
    for(int i=0;i<m;i++)
    {
        cin>>p[i].fi>>p[i].se;
    }
    cnt=n;
    vector<ll>ans(m);
    for(int i=m-1;i>=0;i--)
    {
        val=(n*n-cnt)/2;
        ans[i]=val;
        Union(p[i].fi,p[i].se);
    }
    for(auto itr:ans)
    {
        cout<<itr<<endl;
    }
}

Compiler output:
a.cc: In function 'void init()':
a.cc:55:9: error: reference to 'visit' is ambiguous
   55 |         visit[i]=i;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn],sz[maxn],cnt=0;
      |    ^~~~~
a.cc: In function 'long long int find(long long int)':
a.cc:61:8: error: reference to 'visit' is ambiguous
   61 |     if(visit[x]!=x)
      |        ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn],sz[maxn],cnt=0;
      |    ^~~~~
a.cc:63:16: error: reference to 'visit' is ambiguous
   63 |         return visit[x]=find(visit[x]);
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn],sz[maxn],cnt=0;
      |    ^~~~~
a.cc:63:30: error: reference to 'visit' is ambiguous
   63 |         return visit[x]=find(visit[x]);
      |                              ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn],sz[maxn],cnt=0;
      |    ^~~~~
a.cc: In function 'void Union(long long int, long long int)':
a.cc:78:5: error: reference to 'visit' is ambiguous
   78 |     visit[val]=val1;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn],sz[maxn],cnt=0;
      |    ^~~~~