Codeforces Round #524 (Div. 2)

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:

刚开始以为是开关问题,后来发现数据太大,从题目中不难发现一个规律,当m,n全为奇数的时候,白格比黑格多一个,其他情况均相同,在选中的矩形框内,同样的道理,若左下角为黑格,则黑格多一个,反之白格多一个,处理矩形分两种情况,一种两个矩形均不相交,第二种矩形相交;

判断两个矩形是否相交,只需判断第一个矩形的右上角坐标是否大于等于第二个矩形的左下角坐标即可; 

昨晚也真是,这么简单的模拟……掉分了又

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int t;
    long long x1,y1,x2,y2,x3,y3,x4,y4,n,m;
    long long cnt_w,cnt_b,sum1,sum2,cnt_tw,cnt_tb;
    scanf("%d",&t);
    while(t--)
    {
        cnt_b=0,cnt_w=0;
        scanf("%I64d%I64d",&n,&m);
        scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);
        scanf("%I64d%I64d%I64d%I64d",&x3,&y3,&x4,&y4);
        if(n%2==1&&m%2==1)  //如果为均为奇,white多一个,否则相等
        {
            cnt_w=n*m/2+1;
            cnt_b=n*m/2;
        }
        else
        {
            cnt_w=cnt_b=m*n/2;
        }
        if((x1+y1)%2==0)   //左下角为white
        {
            cnt_w=cnt_w+(x2-x1+1)*(y2-y1+1)/2;
            cnt_b=cnt_b-(x2-x1+1)*(y2-y1+1)/2;

        }
        else    //为黑色
        {
            if((x2-x1+1)%2==1&&(y2-y1+1)%2==1)
            {
                cnt_w+=((x2-x1+1)*(y2-y1+1)/2+1);
                cnt_b-=((x2-x1+1)*(y2-y1+1)/2+1);
            }
            else
            {
                cnt_w+=(x2-x1+1)*(y2-y1+1)/2;
                cnt_b-=(x2-x1+1)*(y2-y1+1)/2;
            }
        }
        if((x3+y3)%2==0)
        {
            if((x4-x3+1)%2==1&&(y4-y3+1)%2==1)
            {
                cnt_b+=((x4-x3+1)*(y4-y3+1)/2+1);
                cnt_w-=((x4-x3+1)*(y4-y3+1)/2+1);
            }
            else
            {
                cnt_b+=(x4-x3+1)*(y4-y3+1)/2;
                cnt_w-=(x4-x3+1)*(y4-y3+1)/2;
            }

        }
        else   //为黑色
        {

            cnt_b+=(x4-x3+1)*(y4-y3+1)/2;
            cnt_w-=(x4-x3+1)*(y4-y3+1)/2;

        }
        //处理相交
        long long n1,n2,m1,m2;
        n1=min(max(x1,x2),max(x3,x4));
        m1=min(max(y1,y2),max(y3,y4));
        n2=max(min(x1,x2),min(x3,x4));
        m2=max(min(y1,y2),min(y3,y4));
        if(n1>=n2&&m1>=m2)
        {
            swap(n1,n2);
            swap(m1,m2);
            if((n1+m1)%2==0)
            {
                    cnt_b+=(n2-n1+1)*(m2-m1+1)/2;
                    cnt_w-=(n2-n1+1)*(m2-m1+1)/2;

            }
            else
            {
                if((n2-n1+1)%2 == 1 && (m2-m1+1)%2 == 1)
                {
                    cnt_b+= ((n2-n1+1)*(m2-m1+1)/2+1);
                    cnt_w-= ((n2-n1+1)*(m2-m1+1)/2+1);
                }
                else
                {
                    cnt_b+= (n2-n1+1)*(m2-m1+1)/2;
                    cnt_w-= (n2-n1+1)*(m2-m1+1)/2;
                }
            }
        }
        printf("%lld %lld\n",cnt_w,cnt_b);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值