CF1080C.Masha and two friends

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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)(x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x3,y3,x4,y4)(x_3,y_3,x_4,y_4).

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!

最近,玛莎收到了一块尺寸为 nn 行(高)×\times mm 列(宽)的国际象棋棋盘。

棋盘的行从下到上编号为 11 到 nn;列从左到右编号为 11 到 mm。因此,每个格子可用坐标 (x,y)(x,y) 表示,其中 xx 为列号,yy 为行号(请注意不要混淆)。

我们称坐标为 (a,b,c,d)(a,b,c,d) 的矩形为:其左下角顶点坐标为 (a,b)(a,b),右上角顶点坐标为 (c,d)(c,d)。

该棋盘按如下方式涂成黑白两色:

棋盘的一个示例。

玛莎对这份礼物非常开心,于是邀请了朋友马克西姆和丹尼斯来一起欣赏。两位朋友决定给她一个惊喜——他们买了一罐白色油漆和一罐黑色油漆,以便在旧棋盘损坏时可以重新涂刷。当他们来到玛莎家时,发生了一件不愉快的事:首先,马克西姆刚跨过门槛,就将白色油漆洒在了矩形区域 (x1,y1,x2,y2)(x_1,y_1,x_2,y_2) 上;随后,丹尼斯又将黑色油漆洒在了矩形区域 (x3,y3,x4,y4)(x_3,y_3,x_4,y_4) 上。

向某个矩形区域泼洒颜色为 colorcolor 的油漆,意味着该矩形内所有格子均变为 colorcolor。格子的染色是叠加进行的(例如:若某格子先被泼上白色油漆、后又被泼上黑色油漆,则其最终颜色为黑色)。

玛莎震惊了!她把客人们赶走,决定弄清楚这份礼物被毁坏得有多严重。为此,她需要知道当前棋盘上白色格子与黑色格子的数量。请帮她计算出这两个数值!

输入格式

The first line contains a single integer tt (1≤t≤1031 \le t \le 10^3) — 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 \le n,m \le 10^9) — the size of the board.

The second line contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (1≤x1≤x2≤m,1≤y1≤y2≤n1 \le x_1 \le x_2 \le m, 1 \le y_1 \le y_2 \le n) — the coordinates of the rectangle, the white paint was spilled on.

The third line contains four integers x3x_3, y3y_3, x4x_4, y4y_4 (1≤x3≤x4≤m,1≤y3≤y4≤n1 \le x_3 \le x_4 \le m, 1 \le y_3 \le y_4 \le n) — the coordinates of the rectangle, the black paint was spilled on.

第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3)—— 测试用例的数量。

每个测试用例的描述格式如下:

第一行包含两个整数 nn 和 mm(1≤n,m≤1091 \le n,m \le 10^9)—— 棋盘的尺寸。

第二行包含四个整数 x1x_1、y1y_1、x2x_2、y2y_2(1≤x1≤x2≤m1 \le x_1 \le x_2 \le m,1≤y1≤y2≤n1 \le y_1 \le y_2 \le n)—— 白色颜料泼洒区域的矩形坐标。

第三行包含四个整数 x3x_3、y3y_3、x4x_4、y4y_4(1≤x3≤x4≤m1 \le x_3 \le x_4 \le m,1≤y3≤y4≤n1 \le y_3 \le y_4 \le n)—— 黑色颜料泼洒区域的矩形坐标。

输出格式

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

输出 tt 行,每行包含两个数字——分别为泼洒油漆后白色格子与黑色格子的数量。

输入输出样例

  • 输入#1

    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

    输出#1

    0 4
    3 9
    2 3
    8 8
    4 8

说明/提示

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:

示例说明:

每幅插图的第一张图片展示了染料泼洒前田地的原始状态;第二张图片展示了马克西姆泼洒白色染料后田地的状态(泼洒染料的矩形区域以红色高亮显示);第三张图片展示了丹尼斯泼洒黑色染料后田地的状态(泼洒染料的矩形区域以红色高亮显示)。

在第一个测试用例中,田地上的颜料变化过程如下:

在第二个测试用例中,田地上的颜料变化过程如下:

在第三个测试用例中,田地上的颜料变化过程如下:

在第四个测试用例中,田地上的颜料变化过程如下:

在第五个测试用例中,田地上的颜料变化过程如下:

输入解题思路,AI测评打分。不知道怎么写?

首页