1. 程式人生 > >Codeforces Round #524 (Div. 2) C. Masha and two friends

Codeforces Round #524 (Div. 2) C. Masha and two friends

C. Masha and two friends

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently, Masha was presented with a chessboard with a height of nn and a width of mm.

The rows on the chessboard are numbered from 11 to nn from bottom to top. The columns are numbered from 11 to mm from left to right. Therefore, each cell can be specified with the coordinates (x,y)(x,y), where xx is the column number, and yy is the row number (do not mix up).

Let us call a rectangle with coordinates (a,b,c,d)(a,b,c,d) a rectangle lower left point of which has coordinates (a,b)(a,b), and the upper right one — (c,d)(c,d).

The chessboard is painted black and white as follows:

An example of a chessboard.

Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x1,y1,x2,y2)(x1,y1,x2,y2). Then after him Denis spilled black paint on the rectangle (x3,y3,x4,y4)(x3,y3,x4,y4).

To spill paint of color colorcolor onto a certain rectangle means that all the cells that belong to the given rectangle become colorcolor. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).

Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!

Input

The first line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases.

Each of them is described in the following format:

The first line contains two integers nn and mm (1≤n,m≤1091≤n,m≤109) — the size of the board.

The second line contains four integers x1x1, y1y1, x2x2, y2y2 (1≤x1≤x2≤m,1≤y1≤y2≤n1≤x1≤x2≤m,1≤y1≤y2≤n) — the coordinates of the rectangle, the white paint was spilled on.

The third line contains four integers x3x3, y3y3, x4x4, y4y4 (1≤x3≤x4≤m,1≤y3≤y4≤n1≤x3≤x4≤m,1≤y3≤y4≤n) — the coordinates of the rectangle, the black paint was spilled on.

Output

Output tt lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.

Example

input

Copy

5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3

output

Copy

0 4
3 9
2 3
8 8
4 8

Note

Explanation for examples:

The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).

In the first test, the paint on the field changed as follows:

In the second test, the paint on the field changed as follows:

In the third test, the paint on the field changed as follows:

In the fourth test, the paint on the field changed as follows:

In the fifth test, the paint on the field changed as follows:

分析:

我們可以只算黑色塊增加數b,白色塊等於n*m-b

b=第二區域白(到黑)的數量-第一區域黑(到白)的數量+重合部分的黑色數量

然後就是求各個區域黑色和白色的數量,注意規律。

#include<cstdio>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<functional>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<map>
using namespace std;
#define N 100000+5
#define rep(i,n) for(int i=0;i<n;i++)
#define sd(n) scanf("%d",&n)
#define sll(n) scanf("%I64d",&n)
#define pd(n) scanf("%d\n",n)
#define pll(n) scanf("%I64d\n",n)
#define MAX 26
typedef long long ll;
const ll mod=1e9+7;
ll n,m;

//ll b[N];
int main()
{
	 //string s;
	 //cin>>s;
	 //ll ans=0;
	 //ll sum=0;
	 int t;
	 scanf("%d",&t);
	 while(t--)
	 {
	  scanf("%I64d",&n);
	  scanf("%I64d",&m);
	  if(n<m) {swap(n,m);}
	  
	  ll b;
	  if(n%2==1 && m%2 == 1)
	{
       b= (n*m) / 2;
    }
    else  b = (n*m)/2;
	
	//cout<<b<<endl;
	ll x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
	scanf("%I64d%I64d",&x1,&y1);
	scanf("%I64d%I64d",&x2,&y2);
	scanf("%I64d%I64d",&x3,&y3);
	scanf("%I64d%I64d",&x4,&y4);
	x5=max(x1,x3);
	x6=min(x2,x4);
	y5=max(y1,y3);
	y6=min(y2,y4);

	ll b1=(x2-x1+1)*(y2-y1+1)/2;//求第一區域黑色數量
	if((x1+y1)%2==1&&(x2-x1+1)%2==1&&(y2-y1+1)%2==1)
		b1++;
		
	ll a2=(x4-x3+1)*(y4-y3+1)/2;//求第二區域白色數量
	if((x3+y3)%2==0&&(x4-x3+1)%2==1&&(y4-y3+1)%2==1)
		a2++;
	
	
	ll b3=0;//求重合部分黑色數量
	if(x6>=x5&&y6>=y5)
	{
		b3=(x6-x5+1)*(y6-y5+1)/2;
		if((x5+y5)%2==1&&(x6-x5+1)%2==1&&(y6-y5+1)%2==1)
		b3++;
	}
	
    b+=a2+b3-b1;;
	ll w=m*n-b;
	printf("%I64d %I64d\n",w,b);
	}
	 
	
    return 0;
}