Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>

using namespace std;

#include <iostream>


#define ll   long long
#define F first
#define S second

void __print(int x) { cout << x; }

void __print(long x) { cout << x; }

void __print(long long x) { cout << x; }

void __print(unsigned x) { cout << x; }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << '{';
    __print(x.first);
    cout << ',';
    __print(x.second);
    cout << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cout << '{';
    for (auto &i: x) cout << (f++ ? "," : ""), __print(i);
    cout << "}";
}

void _print() { cout << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cout << ", ";
    _print(v...);
}


template<class S,
        S (*op)(S, S),
        S (*e)(),
        class F,
        S (*mapping)(F, S),
        F (*composition)(F, F),
        F (*id)()>
struct lazy_segtree {
public:

    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }

    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};


#ifdef LOCAL
#else
#define dbg(x...)
#endif
struct F {
    int b; // denotes the mapping "multiply by b"
};
using S = int;

S op(S x, S y) { return min(x, y); }

S e() { return 1e9; }

S mapping(F f, S x) { return min(f.b, x); }

F composition(F f, F g) { return F{min(f.b, g.b)}; }

F id() { return F{(int) 1e7}; }

class FSimplifiedReversi {
public:

    void solve2(std::istream &cin, std::ostream &cout) {

        int n, q;
        cin >> n >> q;
        vector<int> col(n + 1, n), row(n + 1, n);
        col[n] = 1, row[n] = 1;
        lazy_segtree<S, op, e, F, mapping, composition, id> C(col), R(row);
        ll ans = (ll) (n - 2) * (n - 2);
        for (int i = 0; i < q; ++i) {
            int t, x;
            cin >> t >> x;
            if (t == 1) {
                int hi = C.get(x);
                ans -= hi - 2;
                R.apply(1, hi, F{x});
                C.apply(x, x, F{1});
            } else {
                int hi = R.get(x);
                ans -= hi - 2;
                C.apply(1, hi, F{x});
                R.apply(x, x, F{1});
            }
        }
        cout << ans;


    }

    void solve(std::istream &cin, std::ostream &cout) {
        ll t = 1;
//            cin >> t;
        while (t--) {
            solve2(cin, cout);
        }
    }

};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    FSimplifiedReversi solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Compiler output:
a.cc: In member function 'void FSimplifiedReversi::solve2(std::istream&, std::ostream&)':
a.cc:149:66: error: no matching function for call to 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(std::vector<int>&)'
  149 |         lazy_segtree<S, op, e, F, mapping, composition, id> C(col), R(row);
      |                                                                  ^
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree()'
   61 | struct lazy_segtree {
      |        ^~~~~~~~~~~~
a.cc:61:8: note:   candidate expects 0 arguments, 1 provided
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(const lazy_segtree<int, op, e, first, mapping, composition, id>&)'
a.cc:61:8: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const lazy_segtree<int, op, e, first, mapping, composition, id>&'
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(lazy_segtree<int, op, e, first, mapping, composition, id>&&)'
a.cc:61:8: note:   no known conversion for argument 1 from 'std::vector<int>' to 'lazy_segtree<int, op, e, first, mapping, composition, id>&&'
a.cc:149:74: error: no matching function for call to 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(std::vector<int>&)'
  149 |         lazy_segtree<S, op, e, F, mapping, composition, id> C(col), R(row);
      |                                                                          ^
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree()'
   61 | struct lazy_segtree {
      |        ^~~~~~~~~~~~
a.cc:61:8: note:   candidate expects 0 arguments, 1 provided
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(const lazy_segtree<int, op, e, first, mapping, composition, id>&)'
a.cc:61:8: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const lazy_segtree<int, op, e, first, mapping, composition, id>&'
a.cc:61:8: note: candidate: 'lazy_segtree<int, op, e, first, mapping, composition, id>::lazy_segtree(lazy_segtree<int, op, e, first, mapping, composition, id>&&)'
a.cc:61:8: note:   no known conversion for argument 1 from 'std::vector<int>' to 'lazy_segtree<int, op, e, first, mapping, composition, id>&&'