Language: C

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

#define N 3100
#define lef(x) (((x)<<1)+1)
#define rig(x) (((x)<<1)+2)

int h[N], e[N], thick[N], Oceng[N], Tceng[N];

int apx[N], apy[N], apz[N];//o to r
int _x[N][2], _y[N][2], _z[N][2];
map<int, int> x, y;// real to reorder

int length(int loc){
	return apy[e[loc]] - apy[h[loc]];
}

void build(int he, int en, int loc){
	h[loc] = he, e[loc] = en;
	if(he+1>=en){
		return;
	}
	int mid = he+en>>1;
	build(he, mid, lef(loc));
	build(mid, en, rig(loc));
}
void statis(int loc){
	if(thick[loc] >= 2){
		Tceng[loc] = length(loc);
		Oceng[loc] = 0;
		return;
	}
	if(h[loc] +1>=e[loc]){
		if(thick[loc] >= 2){
			Tceng[loc] = length(loc);
			Oceng[loc] = 0;
		}
		else if(thick[loc]){
			Oceng[loc]=length(loc);
			Tceng[loc]=0;
		}
		else
			Tceng[loc] = Oceng[loc] =0;
		return;
	}

	Tceng[loc] = Tceng[lef(loc)]+Tceng[rig(loc)];
	Oceng[loc] = Oceng[lef(loc)]+Oceng[rig(loc)];
	if(thick[loc]){
		Tceng[loc] += Oceng[loc];
		Oceng[loc] =length(loc)-Tceng[loc];
	}
}
void insert(int he, int en, int loc){
	if(h[loc] == he&& e[loc] == en){
		thick[loc]++;
	}
	else{
		int mid = h[loc]+e[loc]>>1;
		insert(he, mid, lef(loc));
		insert(mid, en, rig(loc));
	}
	statis(loc);
}
void del(int he, int en, int loc){
	if(h[loc] == he && e[loc] ==en)
		thick[loc]--;
	else{
		int mid = h[loc]+e[loc]>>1;
		del(he, mid, lef(loc));
		del(mid, en, rig(loc));
	}
	statis(loc);
}

struct line{
	int up, down, x, z1, z2;
	bool in;
} work[N];
bool operator <(line a, line b){
	if(a.x!=b.x)return a.x<b.x;
	return a.in>b.in;
}

int t, n, zzz;

bool judge(line a){
	if(a.z1<=zzz && a.z2>=zzz+1)return true;
	return false;
}

int main(){
	build(0 , 1000, 0);
	scanf("%d", &t);
	for(int cas = 1; cas<=t; cas++){
		scanf("%d", &n);
		for(int i=0; i<n; i++){
			for(int j=0; j<2; j++){
				scanf("%d%d%d", &_x[i][j], &_y[i][j], &_z[i][j]);
			}
			apx[2*i] = _x[i][0], apy[2*i] = _y[i][0], apz[2*i] = _z[i][0];
			apx[2*i+1] = _x[i][1], apy[2*i+1] = _y[i][1], apz[2*i+1] = _z[i][1];
			work[2*i+1].z1=work[2*i].z1=_z[i][0];
			work[2*i+1].z2=work[2*i].z2=_z[i][1];
			work[2*i+1].up=work[2*i].up = _y[i][0];
		        work[2*i+1].down=work[2*i].down = _y[i][1];
			work[2*i].x = _x[i][0], work[2*i].in = true;
			work[2*i+1].in = false;work[2*i+1].x=_x[i][1];
		}
		sort(apx, apx+2*n), sort(apy, apy+2*n), sort(apz, apz+2*n);
		sort(work, work+2*n);
		int usedx = 0, usedy = 0;
		for(int i=0; i<2*n; i++){
			if(x.find(apx[i]) == x.end()){
				x[apx[i]] = usedx;
				usedx++;
			}
			if(y.find(apy[i]) == y.end()){
				y[apy[i]] = usedy;
				usedy++;
			}
		}
		usedx = 0;
		map<int, int>::iterator it = x.begin();
		for(;it!=x.end();it++, usedx++){
			apx[usedx] = it->first;
		}
		usedy = 0; it = y.begin();
		for(;it!=y.end();it++, usedy++){
			apy[usedy] = it->first;
		}
		for(int i=0; i<2*n; i++)
			work[i].up = apy[work[i].up],
			work[i].down = apy[work[i].down];
		long long ans = 0;
		for(int zz = -505; zz<505; zz++){
			zzz = zz;
			memset(thick, 0, sizeof thick);
			memset(Oceng, 0, sizeof Oceng);
			memset(Tceng, 0, sizeof Tceng);
			int pre = -10000000;
			for(int i=0; i<2*n; i++){
				if(judge(work[i])){
					ans += (work[i].x-pre)*Tceng[0];
					if(work[i].in) insert(work[i].up, work[i].down, 0);
					else		del(work[i].up, work[i].down, 0);
					pre = work[i].x;
				}
			}
		}
		cout<<"Case "<<cas<<": "<<ans<<endl;
		//printf("Case %d: %I64d\n",cas, ans);
		x.clear(), y.clear();
	}
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.