Language: C++

#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

const ll MOD = 1e9 + 7;
const int N = 3010;

#define all(x) (x).begin(), (x).end()
#define int long long

int a[N], b[N], c[N], d[N], e[N], f[N];
vector<int> x, y;
int n, m, h, w;
long long s[N][N];
int F[N][N];
int xline[N], yline[N];
int cx[4] = {0, 1, 0, -1};
int cy[4] = {1, 0, -1, 0};
int ok(int x, int y)
{
    return 0 <= x && x < w && 0 <= y && y < h && F[y][x] == 0;
}
void demon()
{
    return;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << F[i][j];
        }
        cout << "\n";
    }
}
ll Sq(int i, int j)
{
    if (i % 2 == 0 && j % 2 == 0)
    {
        return (xline[j + 1] - xline[j - 1]) * (yline[i + 1] - yline[i - 1]);
    }
    return 0;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        x.push_back(a[i]);
        x.push_back(b[i]);
        y.push_back(c[i]);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> d[i] >> e[i] >> f[i];
        x.push_back(d[i]);
        y.push_back(e[i]);
        y.push_back(f[i]);
    }
    x.push_back(0);
    y.push_back(0);
    sort(all(x));
    x.resize(unique(all(x)) - x.begin());
    sort(all(y));
    y.resize(unique(all(y)) - y.begin());
    for (int i = 0; i < x.size(); i++)
    {
        xline[2 * i + 1] = x[i];
    }
    for (int i = 0; i < y.size(); i++)
    {
        yline[2 * i + 1] = y[i];
    }
    h = x.size() * 2 + 1;
    w = y.size() * 2 + 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < w; j += 2)
        {
            if (yline[j] == c[i])
            {
                //cout << "ENTER" << endl;
                //cout << a[i] << " < " << b[i] << " " << j << endl;
                int t = 0;
                for (int k = 0; k < h; k++)
                {
                    if (k % 2 == 1 && xline[k] == a[i]) t = 1;
                    if (t) F[k][j] = 1;
                    if (k % 2 == 1 && xline[k] == b[i]) t = 0;
                }
            }
        }
    }
    demon();
    for (int i = 0; i < m; i++)
    {
        for (int j = 1; j < h; j += 2)
        {
            if (xline[j] == d[i])
            {
                //cout << "ENTER" << endl;
                //cout << e[i] << " < " << f[i] << " " << j << endl;
                int t = 0;
                for (int k = 0; k < w; k++)
                {
                    if (k % 2 == 1 && yline[k] == e[i]) t = 1;
                    if (t) F[j][k] = 1;
                    if (k % 2 == 1 && yline[k] == f[i]) t = 0;
                }
            }
        }
    }
    demon();
    vector<pair<int, int> > s;
    ll ans = 0;
    for (int i = 1; i < w; i += 2)
        for (int j = 1; j < h; j += 2)
    if (yline[i] == 0 && xline[j] == 0) s.push_back({i, j}), ans += Sq(i, j), F[i][j] = 2;
    for (int i = 0; i < s.size(); i++)
    {
        for (int k = 0; k < 4; k++)
        {
            int nx = s[i].first + cx[k];
            int ny = s[i].second + cy[k];
            if (ok(nx, ny))
            {
                if (nx == 0 || nx == w - 1 || ny == 0 || ny == h - 1) cout << "INF", exit(0);
                s.push_back({nx, ny});
                ans += Sq(nx, ny);
                F[nx][ny] = 2;
            }
        }
    }
    return 1;
    demon();
    cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:68:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   68 |     sort(all(x));
      |     ^~~~
      |     short
a.cc:69:14: error: 'unique' was not declared in this scope
   69 |     x.resize(unique(all(x)) - x.begin());
      |              ^~~~~~