Language: C++

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#include <atcoder/lazysegtree>
using namespace atcoder;

//-------------------------------------

int op(int a, int b) { return min(a, b); }
int e() { return INF; }
int mapping(int f, int x) { return min(f, x); }
int composition(int f, int g) { return min(f, g); }
int id() { return INF; }

int main() {
    int n, q;
    cin >> n >> q;
    lazy_segtree<int, op, e, int, mapping, composition, id> r(n), c(n);
    for(int i = 0; i < n; i++) {
        r.set(i, n - 1);
        c.set(i, n - 1);
    }
    while(q--) {
        int t, x;
        cin >> t >> x;
        x--;
        if(t == 1) {
            int R = c.get(x);
            c.set(x, 1);
            r.apply(1, R, x);
        } else {
            int R = r.get(x);
            r.set(x, 1);
            c.apply(1, R, x);
        }
        // for(int i = 1; i < n - 1; i++) {
        //     cerr << r.get(i) << " ";
        // }
        // cerr << "\n";
        // for(int i = 1; i < n - 1; i++) {
        //     cerr << c.get(i) << " ";
        // }
        // cerr << "\n";
    }
    ll ans = 0;
    for(int i = 1; i < n - 1; i++) {
        ans += r.get(i) - 1;
        ans += c.get(i) - 1;
    }
    int tate = n - 1, yoko = n - 1;
    for(int i = 1; i < n - 1; i++) {
        if(r.get(i) == 1) {
            chmin(tate, i);
        }
        if(c.get(i) == 1) {
            chmin(yoko, i);
        }
    }
    ans -= (ll)(tate - 1) * (ll)(yoko - 1);
    cout << ans << endl;
}

Compiler output:
a.cc:67:10: fatal error: atcoder/lazysegtree: No such file or directory
   67 | #include <atcoder/lazysegtree>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.