Language: C++

// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;

const int N=5e3+100;
const int inf=2e9;
const ll inf2=5e18;

int fx[]={0,0,-1,1};
int fy[]={1,-1,0,0};

bool gfo[N*N*10][5];
bool vst[N][N];
ll area[N*N*10];
int n,m;


int trans(int i,int j){return m*i+j;}

ll sum(ll a,ll b){
	if(a==inf2||b==inf2)return inf2;
	return a+b;
}

void dfs(int y,int x,ll &A){
	vst[y][x]=true;
	A=sum(A,area[trans(y,x)]);
	For(c,0,4)if(gfo[trans(y,x)][c]){
		int yy=y+fy[c];
		int xx=x+fx[c];
		if(xx<0||xx>=m)continue;
		if(yy<0||yy>=n)continue;
		if(vst[yy][xx])continue;
		dfs(yy,xx,A);
	}
}


int main(){	
	cin>>n>>m;
	set<int>X,Y;
	X.insert(inf);X.insert(-inf);
	Y.insert(inf);Y.insert(-inf);
	vector<ii>LH,LV;
	For(i,0,n){
		int a,b,c;cin>>a>>b>>c;
		if(a>b)swap(a,b);
		X.insert(c);
		Y.insert(a);
		Y.insert(b);
		LV.pb({c,a});
		LV.pb({c,b});
	}
	For(i,0,m){
		int d,e,f;cin>>d>>e>>f;
		if(e>f)swap(e,f);
		X.insert(e);
		X.insert(f);
		Y.insert(d);
		LH.pb({e,d});
		LH.pb({f,d});
	}
	vector<ll>XX,YY;
	for(int x: X)XX.pb(x);
	for(int y: Y)YY.pb(y);
	n=sz(Y)-1,m=sz(X)-1;
	For(i,0,sz(YY)-1)For(j,0,sz(XX)-1){
		if(	XX[j]==inf||XX[j]==-inf||XX[j+1]==inf||XX[j+1]==-inf||
			YY[i]==inf||YY[i]==-inf||YY[i+1]==inf||YY[i+1]==-inf)
			area[trans(i,j)]=inf2;
		else area[trans(i,j)]=(YY[i+1]-YY[i])*(XX[j+1]-XX[j]);
	}
	For(i,0,sz(YY)-1)For(j,0,sz(XX)-1){
		For(c,0,4)gfo[trans(i,j)][c]=true;
		if(i==0)gfo[trans(i,j)][1]=false;
		if(i==sz(YY)-2)gfo[trans(i,j)][0]=false;
		if(j==0)gfo[trans(i,j)][3]=false;
		if(j==sz(XX)-2)gfo[trans(i,j)][2]=false;
	}

	for(int i=0;i<sz(LH);i+=2){
		int pos=lower_bound(all(YY),LH[i].ss)-YY.begin();
		For(j,0,sz(XX))if(XX[j]>=LH[i].ff&&XX[j]<LH[i+1].ff){
			gfo[trans(pos-1,j)][0]=false;
			gfo[trans(pos,j)][1]=false;
		}
	}
	for(int i=0;i<sz(LV);i+=2){
		int pos=lower_bound(all(XX),LV[i].ff)-XX.begin();
		For(j,0,sz(YY))if(YY[j]>=LV[i].ss&&YY[j]<LV[i+1].ss){
			gfo[trans(j,pos-1)][3]=false;
			gfo[trans(j,pos)][2]=false;
		}
	}

	//if(sz(LV)==2000||sz(LH)==2000)return 0;

	int iniy=upper_bound(all(YY),0)-YY.begin();
	int inix=upper_bound(all(XX),0)-XX.begin();
	ll A=0;
	//dfs(iniy,inix,A);
	if(A!=inf2)cout<<A<<endl;
	else cout<<"INF"<<endl;
	return 0;
}


Compiler output:
/tmp/ccK6bOEC.o: in function `trans(int, int)':
a.cc:(.text+0xc): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccK6bOEC.o
/tmp/ccK6bOEC.o: in function `dfs(int, int, long long&)':
a.cc:(.text+0x160): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x171): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccK6bOEC.o
/tmp/ccK6bOEC.o: in function `main':
a.cc:(.text+0x1df): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x1fb): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x3f9): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x541): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x6b0): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccK6bOEC.o
a.cc:(.text+0x6c8): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccK6bOEC.o
collect2: error: ld returned 1 exit status