Language: C++

#include<bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18
 



int n,q;
vector<int> a;

struct data
{
    //Use required attributes
    int mn,cnt;

    //Default Values
    data() : mn(1e10) {};
};

struct SegTree
{
    int N;
    vector<data> st;
    vector<bool> cLazy;
    vector<int> lazy;

    void init(int n)
    {
        N = n;
        st.resize(4 * N + 5);
        cLazy.assign(4 * N + 5, false);
        lazy.assign(4 * N + 5, 0);
    }

    //Write reqd merge functions
    void merge(data &cur, data &l, data &r) 
    {
        cur.mn = min(l.mn, r.mn);
    }
    
    //Handle lazy propagation appriopriately
    void propagate(int node, int L, int R)
    {
        if(L != R)
        {
            cLazy[node*2] = 1;
            cLazy[node*2 + 1] = 1;
            if(lazy[node*2]==0) lazy[2*node]=lazy[node];
            else  lazy[node*2] = min(lazy[2*node],lazy[node]);

            if(lazy[node*2+1]==0) lazy[2*node+1]=lazy[node];
            else  lazy[node*2+1] = min(lazy[2*node+1],lazy[node]);

        }
        if(st[node].mn>lazy[node]) st[node].mn=lazy[node]; 
        cLazy[node] = 0;
        lazy[node]=0;
    }

    void build(int node, int L, int R)
    {
        if(L==R)
        {
            st[node].mn = n;
            return;
        }
        int M=(L + R)/2;
        build(node*2, L, M);
        build(node*2 + 1, M + 1, R);
        merge(st[node], st[node*2], st[node*2+1]);
    }

    data Query(int node, int L, int R, int i, int j)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return data();
        if(i<=L && R<=j)
            return st[node];
        int M = (L + R)/2;
        data left=Query(node*2, L, M, i, j);
        data right=Query(node*2 + 1, M + 1, R, i, j);
        data cur;
        merge(cur, left, right);
        return cur;
    }

    data pQuery(int node, int L, int R, int pos)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(L == R)
            return st[node];
        int M = (L + R)/2;
        if(pos <= M)
            return pQuery(node*2, L, M, pos);
        else
            return pQuery(node*2 + 1, M + 1, R, pos);
    }    

    void Update(int node, int L, int R, int i, int j, int val)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return;
        if(i<=L && R<=j)
        {
            cLazy[node] = 1;
            lazy[node] = val;
            propagate(node, L, R);
            return;
        }
        int M = (L + R)/2;
        Update(node*2, L, M, i, j, val);
        Update(node*2 + 1, M + 1, R, i, j, val);
        merge(st[node], st[node*2], st[node*2 + 1]);
    }

    void pUpdate(int node, int L, int R, int pos, int val)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(L == R)
        {
            cLazy[node] = 1;
            if(lazy[node]==0) lazy[node]=val;
            else lazy[node] = min(val,lazy[node]);
            propagate(node, L, R);
            return;
        }
        int M = (L + R)/2;
        if(pos <= M)
            pUpdate(node*2, L, M, pos, val);
        else
            pUpdate(node*2 + 1, M + 1, R, pos, val);
        merge(st[node], st[node*2], st[node*2 + 1]);
    }

    data query(int pos)
    {
        return pQuery(1, 1, N, pos);
    }

    void query(int l, int r)
    {
        data c=Query(1, 1, N, l, r);
        cout<<c.mn<<" "<<c.cnt<<E;

    }

    void update(int pos, int val)
    {
        pUpdate(1, 1, N, pos, val);
    }

    void update(int l, int r, int val)
    {
        Update(1, 1, N, l, r, val);
    }
};

 
  
    





        




int32_t main()
{


    SegTree row,col;
    cin >> n >> q;
    row.init(n);
    col.init(n);
    row.build(1,1,n);   
    col.build(1,1,n);   
       

    int black=(n-2)*(n-2);

        while(q--)
        {
            int a,b;
            cin >> a >> b;
            if(a==1)
            {
               int mx=col.query(b).mn;
               row.update(1,mx,b);
               black-=max(mx-2,0LL);
            }
            else
            {   
                int mx=row.query(b).mn;
                col.update(1,mx,b);
                black-=max(mx-2,0LL);
            }   
        }  

        cout<<black<<endl;
     return 0;
}

Compiler output:
a.cc:47:16: error: template argument 1 is invalid
   47 |     vector<data> st;
      |                ^
a.cc:47:16: error: template argument 2 is invalid
a.cc:60:16: error: reference to 'data' is ambiguous
   60 |     void merge(data &cur, data &l, data &r)
      |                ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:60:16: error: 'data' has not been declared
   60 |     void merge(data &cur, data &l, data &r)
      |                ^~~~
a.cc:60:27: error: reference to 'data' is ambiguous
   60 |     void merge(data &cur, data &l, data &r)
      |                           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:60:27: error: 'data' has not been declared
   60 |     void merge(data &cur, data &l, data &r)
      |                           ^~~~
a.cc:60:36: error: reference to 'data' is ambiguous
   60 |     void merge(data &cur, data &l, data &r)
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:60:36: error: 'data' has not been declared
   60 |     void merge(data &cur, data &l, data &r)
      |                                    ^~~~
a.cc:97:5: error: reference to 'data' is ambiguous
   97 |     data Query(int node, int L, int R, int i, int j)
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:113:5: error: reference to 'data' is ambiguous
  113 |     data pQuery(int node, int L, int R, int pos)
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:165:5: error: reference to 'data' is ambiguous
  165 |     data query(int pos)
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc: In member function 'void SegTree::init(long long int)':
a.cc:54:12: error: request for member 'resize' in '((SegTree*)this)->SegTree::st', which is of non-class type 'int'
   54 |         st.resize(4 * N + 5);
      |            ^~~~~~
a.cc: In member function 'void SegTree::merge(int&, int&, int&)':
a.cc:62:13: error: request for member 'mn' in 'cur', which is of non-class type 'int'
   62 |         cur.mn = min(l.mn, r.mn);
      |             ^~
a.cc:62:24: error: request for member 'mn' in 'l', which is of non-class type 'int'
   62 |         cur.mn = min(l.mn, r.mn);
      |                        ^~
a.cc:62:30: error: request for member 'mn' in 'r', which is of non-class type 'int'
   62 |         cur.mn = min(l.mn, r.mn);
      |                              ^~
a.cc: In member function 'void SegTree::propagate(long long int, long long int, long long int)':
a.cc:79:14: error: invalid types 'int[long long int]' for array subscript
   79 |         if(st[node].mn>lazy[node]) st[node].mn=lazy[node];
      |              ^
a.cc:79:38: error: invalid types 'int[long long int]' for array subscript
   79 |         if(st[node].mn>lazy[node]) st[node].mn=lazy[node];
      |                                      ^
a.cc: In member function 'void SegTree::build(long long int, long long int, long long int)':
a.cc:88:15: error: invalid types 'int[long long int]' for array subscript
   88 |             st[node].mn = n;
      |               ^
a.cc:94:17: error: invalid types 'int[long long int]' for array subscript
   94 |         merge(st[node], st[node*2], st[node*2+1]);
      |                 ^
a.cc:94:27: error: invalid types 'int[long long int]' for array subscript
   94 |         merge(st[node], st[node*2], st[node*2+1]);
      |                           ^
a.cc:94:39: error: invalid types 'int[long long int]' for array subscript
   94 |         merge(st[node], st[node*2], st[node*2+1]);
      |                                       ^
a.cc: In member function 'void SegTree::Update(long long int, long long int, long long int, long long int, long long int, long long int)':
a.cc:142:17: error: invalid types 'int[long long int]' for array subscript
  142 |         merge(st[node], st[node*2], st[node*2 + 1]);
      |                 ^
a.cc:142:27: error: invalid types 'int[long long int]' for array subscript
  142 |         merge(st[node], st[node*2], st[node*2 + 1]);
      |                           ^
a.cc:142:39: error: invalid types 'int[long long int]' for array subscript
  142 |         merge(st[node], st[no