Language: C++

#include<bits/stdc++.h>

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    vector<tuple<ll,ll,ll>> abc(n), def(m), cab(n);
    for(auto &[a, b, c]: abc) cin >> a >> b >> c;
    for(ll i=0; i<n; i++) {
        auto [a, b, c] = abc[i];
        cab[i] = {c, a, b};
    }
    for(auto &[a, b, c]: def) cin >> a >> b >> c;

    sort(cab.begin(), cab.end());
    sort(def.begin(), def.end());

    vector<ll> xs(3*(n+m), 1e10), ys(3*(n+m), 1e10);
    {
        ll xi = 0, yi = 0;
        xs[xi++] = -1e10;
        ys[yi++] = -1e10;

        for(auto &[a, b, c]: abc) {
            xs[xi++] = a;
            xs[xi++] = b;
            ys[yi++] = c;
        }
        for(auto &[d, e, f]: def) {
            xs[xi++] = d;
            ys[yi++] = e;
            ys[yi++] = f;
        }

        sort(xs.begin(), xs.end());
        sort(ys.begin(), ys.end());
        auto xla = unique(xs.begin(), xs.end());
        xs.erase(xla, xs.end());
        auto yla = unique(ys.begin(), ys.end());
        ys.erase(yla, ys.end());
    }

    auto sur = [&](ll x, ll y) -> ll {
        if(xs[x+1] == 1e10 || ys[y+1] == 1e10 || xs[x] == -1e10 || ys[y] == -1e10)
            return 3e18;
        return (xs[x+1] - xs[x]) * (ys[y+1] - ys[y]);
    };

    {
        vector<tuple<ll,ll,ll>> ncab;
        for(ll i=0; i<n; ) {
            vector<pair<ll,ll>> v;
            ll cc = get<0>(cab[i]);

            while(1) {
                auto [c, a, b] = cab[i];
                if(c != cc) break;
                v.push_back({a, 0});
                v.push_back({b, 1});
                i++;
            }
            sort(v.begin(), v.end());

            ll s = 0, p = -1e9;
            for(auto [x, t]: v) {
                if(t == 0) {
                    if(s == 0) p = x;
                    s++;
                } else {
                    s--;
                    if(s == 0) ncab.push_back({cc, p, x});
                }
            }
        }
        cab = ncab;
    }
    {
        vector<tuple<ll,ll,ll>> ndef;
        for(ll i=0; i<m; ) {
            vector<pair<ll,ll>> v;
            ll cc = get<0>(def[i]);

            while(1) {
                auto [c, a, b] = def[i];
                if(c != cc) break;
                v.push_back({a, 0});
                v.push_back({b, 1});
                i++;
            }
            sort(v.begin(), v.end());

            ll s = 0, p = -1e9;
            for(auto [x, t]: v) {
                if(t == 0) {
                    if(s == 0) p = x;
                    s++;
                } else {
                    s--;
                    if(s == 0) ndef.push_back({cc, p, x});
                }
            }
        }
        def = ndef;
    }

    ll si = lower_bound(xs.begin(), xs.end(), 0ll) - xs.begin();
    ll sj = lower_bound(ys.begin(), ys.end(), 0ll) - ys.begin();
    si--, sj--;

    ll res = 0;
    set<pair<ll,ll>> vis;
    {
        auto dfs = [&](auto dfs, ll i, ll j) {
            // cout << '!' << xs[i] << ' ' << ys[j] << endl;
            if(vis.count({i, j})) return;
            vis.insert({i, j});

            res += sur(i, j);
            if(res >= 3e18) {
                cout << "INF" << endl;
                exit(0);
            }
            {
                bool ng = false;
                auto it = lower_bound(def.begin(), def.end(), make_tuple(xs[i], ys[j+1], -1e10));
                it--;
                //for(; it != def.end() && get<0>(*it) == xs[i]; it++) {
                    auto [d, e, f] = *it;
                    if(e <= ys[j] && ys[j+1] <= f) {
                        ng = true;
                        break;
                    }
                //}
                if(!ng) dfs(dfs, i-1, j);
            }
            {
                bool ng = false;
                auto it = lower_bound(def.begin(), def.end(), make_tuple(xs[i+1], ys[j+1], -1e10));
                it--;
                //for(; it != def.end() && get<0>(*it) == xs[i+1]; it++) {
                    auto [d, e, f] = *it;
                    if(e <= ys[j] && ys[j+1] <= f) {
                        ng = true;
                        break;
                    }
                //}
                if(!ng) dfs(dfs, i+1, j);
            }
            {
                bool ng = false;
                auto it = lower_bound(cab.begin(), cab.end(), make_tuple(ys[j], xs[i+1], -1e10));
                it--;
                //for(; it != cab.end() && get<0>(*it) == ys[j]; it++) {
                    auto [c, a, b] = *it;
                    if(a <= xs[i] && xs[i+1] <= b) {
                        ng = true;
                        break;
                    }
                //}
                if(!ng) dfs(dfs, i, j-1);
            }
            {
                bool ng = false;
                auto it = lower_bound(cab.begin(), cab.end(), make_tuple(ys[j+1], xs[i+1], -1e10));
                it--;
                //for(; it != cab.end() && get<0>(*it) == ys[j+1]; it++) {
                    auto [c, a, b] = *it;
                    if(a <= xs[i] && xs[i+1] <= b) {
                        ng = true;
                        break;
                    }
                //}
                if(!ng) dfs(dfs, i, j+1);
            }
        };

        dfs(dfs, si, sj);
    }
    cout << res << endl;

}


Compiler output:
a.cc: In lambda function:
a.cc:139:25: error: break statement not within loop or switch
  139 |                         break;
      |                         ^~~~~
a.cc:152:25: error: break statement not within loop or switch
  152 |                         break;
      |                         ^~~~~
a.cc:165:25: error: break statement not within loop or switch
  165 |                         break;
      |                         ^~~~~
a.cc:178:25: error: break statement not within loop or switch
  178 |                         break;
      |                         ^~~~~