Language: C++

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll get(ll x, ll y){
    return x * 2000 + y;
}
bool visit[2010][2010] = {};

void solve(){
    ll N,M;
    cin >> N >> M;
    ll thre = 100;
    ll A[1010], B[1010], C[1010];
    ll D[1010], E[1010], F[1010];
    map<lpair, bool> is_line;

    rep(i,0,N){
        cin >> A[i] >> B[i] >> C[i];
        A[i] += thre;
        B[i] += thre;
        C[i] += thre;
        rep(j,A[i],B[i]){
            ll v1 = get(j,C[i]), v2 = get(j+1,C[i]);
            is_line[{v1,v2}] = true;
            is_line[{v2,v1}] = true;
        }
    }

    rep(i,0,M){
        cin >> D[i] >> E[i] >> F[i];
        D[i] += thre;
        E[i] += thre;
        F[i] += thre;
        rep(j,E[i],F[i]){
            ll v1 = get(D[i], j), v2 = get(D[i], j+1);
            is_line[{v1,v2}] = true;
            is_line[{v2,v1}] = true;
        }
    }
    queue<lpair> que;
    que.push({thre,thre});
    ll dx[4] = {0,0,1,-1};
    ll dy[4] = {1,-1,0,0};

    while(not que.empty()){
        lpair l1 = que.front();
        que.pop();
        ll x = l1.first, y = l1.second;
        // print(x,y);
        if(x < 0 || y < 0 || x > 3 * thre || y > 3 * thre) continue;
        if(visit[x][y]) continue;
        visit[x][y] = true;
        if(not is_line[{get(x+1, y), get(x+1, y+1)}]){
            if(not visit[x+1][y]) que.push({x+1, y});
        }
        if(not is_line[{get(x, y), get(x, y+1)}]){
            if(not visit[x-1][y]) que.push({x-1, y});
        }
        if(not is_line[{get(x+1, y+1), get(x, y+1)}]){
            if(not visit[x][y+1]) que.push({x, y+1});
        }
        if(not is_line[{get(x+1, y), get(x, y)}]){
            if(not visit[x][y-1]) que.push({x, y-1});
        }
    }
    ll ans = 0;
    rep(i,0,thre*2+1){
        rep(j,0,thre*2+1){
            if(visit[i][j]) ans++;
        }
    }
    if(visit[3*thre][3*thre]){
        print("INF");
    }else{
        print(ans);
    }



    

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:61:12: error: reference to 'visit' is ambiguous
   61 |         if(visit[x][y]) continue;
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:2:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:62:9: error: reference to 'visit' is ambiguous
   62 |         visit[x][y] = true;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:64:20: error: reference to 'visit' is ambiguous
   64 |             if(not visit[x+1][y]) que.push({x+1, y});
      |                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:67:20: error: reference to 'visit' is ambiguous
   67 |             if(not visit[x-1][y]) que.push({x-1, y});
      |                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:70:20: error: reference to 'visit' is ambiguous
   70 |             if(not visit[x][y+1]) que.push({x, y+1});
      |                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:73:20: error: reference to 'visit' is ambiguous
   73 |             if(not visit[x][y-1]) que.push({x, y-1});
      |                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:79:16: error: reference to 'visit' is ambiguous
   79 |             if(visit[i][j]) ans++;
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~
a.cc:82:8: error: reference to 'visit' is ambiguous
   82 |     if(visit[3*thre][3*thre]){
      |        ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:17:6: note:                 'bool visit [2010][2010]'
   17 | bool visit[2010][2010] = {};
      |      ^~~~~