Language: C++

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct L {
  int a, b, c;
};

int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

signed main() {
  int N, M;
  cin >> N >> M;

  vector<L> xx, yy;
  map<int, int> mx, my;
  mx[0] = 0;
  my[0] = 0;

  REP(i, N){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    mx[b] = 0;
    my[c] = 0;
    xx.emplace_back(a, b, c);
  }
  REP(i, M){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    my[b] = 0;
    my[c] = 0;
    xx.emplace_back(a, b, c);
  }

  vector<int> xs, ys;
  for(auto& p : mx){
    p.second = xs.size();
    xs.emplace_back(p.first);
  }
  for(auto& p : my){
    p.second = ys.size();
    ys.emplace_back(p.first);
  }

  int sx = mx[0]*2;
  int sy = my[0]*2;

  int H = xs.size()*2;
  int W = ys.size()*2;
  vector<vector<int>> d(H, vector<int>(W));
  d[sx][sy] = 1;

  REP(i, N){
    int a = mx[xx[i].a]*2;
    int b = mx[xx[i].b]*2;
    int c = my[xx[i].c]*2;
    FOR(j, a, b+1) d[j][c] = -1;
  }
  REP(i, M){
    int a = mx[yy[i].a]*2;
    int b = my[yy[i].b]*2;
    int c = my[yy[i].c]*2;
    FOR(j, b, c+1) d[a][j] = -1;
  }

  queue<pair<int, int>> q;
  q.emplace(sx, sy);

  while(!q.empty()){
    auto [x, y] = q.front(); q.pop();

    REP(i, 4){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(OUT(0, nx, H) || OUT(0, ny, W)) continue;
      if(d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }

  int ans = 0;
  REP(i, H) REP(j, W){
    if(d[i][j] != 1) continue;
    if(i%2 == 0 || j%2 == 0) continue;
    if(i == 0 || i == H-1 || j == 0 || j == W-1){
      cout << "INF" << "\n";
      return 0;
    }
    int ex = xs[i/2+1]-xs[i/2];
    int ey = ys[i/2+1]-ys[i/2];
    ans += ex*ey;
  }

  cout << ans << "\n";

  return 0;
}

Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = L; _Args = {long long int&, long long int&, long long int&}; _Tp = L]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = L; _Args = {long long int&, long long int&, long long int&}; _Tp = L; allocator_type = std::allocator<L>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {long long int&, long long int&, long long int&}; _Tp = L; _Alloc = std::allocator<L>; reference = L&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:70:20:   required from here
   70 |     xx.emplace_back(a, b, c);
      |     ~~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'L::L(long long int&)'
a.cc:48:8: note: candidate: 'L::L()'
   48 | struct L {
      |        ^
a.cc:48:8: note:   candidate expects 0 arguments, 1 provided
a.cc:48:8: note: candidate: 'constexpr L::L(const L&)'
a.cc:48:8: note:   no known conversion for argument 1 from 'long long int' to 'const L&'
a.cc:48:8: note: candidate: 'constexpr L::L(L&&)'
a.cc:48:8: note:   no known conversion for argument 1 from 'long long int' to 'L&&'