Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int n, m;
ll sx, sy;
ll rx, ry;
vector<vector<bool>> yb;
vector<vector<bool>> xb;
vector<vector<bool>> visited;
ll ans = 0;
VI xw(4020);
VI yw(4020);
bool ff = 0;

void dfs(ll x, ll y) {
    if (visited[x][y]) return;
    // cout << x << " " << y << " " << ans << endl;
    if (ff) return;
    if (x == 0 && y == 0) {
        ff = 1;
        return;
    }
    visited[x][y] = 1;
    ans += xw[x] * yw[y];
    if (x > 0 && xb[x][y]) dfs(x - 1, y);
    if (x < rx - 2 && xb[x + 1][y]) dfs(x + 1, y);
    if (y > 0 && yb[x][y]) dfs(x, y - 1);
    if (y < ry - 2 && yb[x][y + 1]) dfs(x, y + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    cin >> n >> m;
    ll a[n], b[n], c[n];
    ll d[m], e[m], f[m];
    VI xs, ys;
    map<ll, ll> zx, zy;
    xs.pb(-inf);
    xs.pb(inf);
    ys.pb(-inf);
    ys.pb(inf);
    xs.pb(0ll);
    ys.pb(0ll);
    for (i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        xs.pb(a[i]);
        xs.pb(b[i]);
        ys.pb(c[i]);
    }
    for (i = 0; i < m; i++) {
        cin >> d[i] >> e[i] >> f[i];
        xs.pb(d[i]);
        ys.pb(e[i]);
        ys.pb(f[i]);
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    for (i = 0; i < xs.size(); i++) {
        if (i + 1 < xs.size()) xw[i] = xs[i + 1] - xs[i];
        zx[xs[i]] = i;
        if (xs[i] == 0) sx = i;
    }
    for (i = 0; i < ys.size(); i++) {
        if (i + 1 < ys.size()) yw[i] = ys[i + 1] - ys[i];
        zy[ys[i]] = i;
        if (ys[i] == 0) sy = i;
    }
    rx = xs.size();
    ry = ys.size();
    yb = vector<vector<bool>>(r + 1, vector<bool>(r + 1, 1));
    xb = vector<vector<bool>>(r + 1, vector<bool>(r + 1, 1));
    visited = vector<vector<bool>>(r + 1, vector<bool>(r + 1, 0));
    for (i = 0; i < n; i++) {
        a[i] = zx[a[i]];
        b[i] = zx[b[i]];
        c[i] = zy[c[i]];
        for (j = a[i]; j < b[i]; j++) {
            yb[j][c[i]] = 0;
        }
    }
    for (i = 0; i < m; i++) {
        d[i] = zx[d[i]];
        e[i] = zy[e[i]];
        f[i] = zy[f[i]];
        for (j = e[i]; j < f[i]; j++) {
            xb[d[i]][j] = 0;
        }
    }
    dfs(sx, sy);
    if (ff) {
        cout << "INF" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:103:31: error: 'r' was not declared in this scope
  103 |     yb = vector<vector<bool>>(r + 1, vector<bool>(r + 1, 1));
      |                               ^