直接贴代码:
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long ll;
ll n,m;
ll w,b;
struct Node
{
ll low,high;
int is;
};
struct Node1
{
ll w,b;
};
Node ok(ll x1,ll x2,ll x3,ll x4)
{
Node t;
ll xx1=max(x1,x3);
ll xx2=min(x2,x4);
if(xx1<=xx2)
{
t.is=1;
t.low=xx1;t.high=xx2;
}
else t.is=0;
return t;
}
Node1 getnumber(ll x1,ll y1,ll x2,ll y2)
{
Node1 t;
ll b1,w1;
if((x2-x1+1)*(y2-y1+1)%2==0)
{
b1=(x2-x1+1)*(y2-y1+1)/2;
w1=b1;
}
else
{
if((x1+y1)%2==0)
{
b1=(x2-x1+1)*(y2-y1+1)/2;
w1=b1+1;
}
else
{
b1=(x2-x1+1)*(y2-y1+1)/2+1;
w1=b1-1;
}
}
t.b=b1;
t.w=w1;
return t;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ll x1,y1,x2,y2,x3,y3,x4,y4;
ll b1,w1;
Node t1,t2;
ll bb,ww;
Node1 t,tt;
cin>>n>>m;
if(n*m%2==0)
{
w=n*m/2;
b=w;
}
else
{
b=n*m/2;
w=b+1;
}
cin>>x1>>y1>>x2>>y2;
cin>>x3>>y3>>x4>>y4;
t=getnumber(x1,y1,x2,y2);
b-=t.b;w+=t.b;
t1=ok(x1,x2,x3,x4);
t2=ok(y1,y2,y3,y4);
if(t1.is&&t2.is)
{
t=getnumber(t1.low,t2.low,t1.high,t2.high);
tt=getnumber(x3,y3,x4,y4);
ll lw=tt.w-t.w;
ll lb=tt.b-t.b;
b+=(t1.high-t1.low+1)*(t2.high-t2.low+1);
w-=(t1.high-t1.low+1)*(t2.high-t2.low+1);
b+=lw;
w-=lw;
}
else
{
tt=getnumber(x3,y3,x4,y4);
b+=tt.w;
w-=tt.w;
}
cout<<w<<" "<<b<<endl;
}
return 0;
}