【CodeForces - 1080C】Masha and two friends

题目描述了一张黑白相间的棋盘,Maxim和Denis分别用白色和黑色油漆涂抹了两个矩形区域。Masha想要知道涂色后,白色和黑色棋格的数量。解决方案是计算原始黑色棋格,减去被覆盖的黑色棋格,加上新的黑色棋格。最后输出白色和黑色棋格数量。
摘要由CSDN通过智能技术生成


@Description@

Recently, Masha was presented with a chessboard with a height of n and a width of m.

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

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

The chessboard is painted black and white as follows:
题目描述图1
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). Then after him Denis spilled black paint on the rectangle (x3,y3,x4,y4).

To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. 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 t (1≤t≤10^3) — the number of test cases.

Each of them is described in the following format:

The first line contains two integers n and m (1≤n,m≤10^9) — the size of the board.

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

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

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

Example
input
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
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:
题目描述图2
In the second test, the paint on the field changed as follows:题目描述图3
In the third test, the paint on the field changed as follows:
题目描述图4
In the fourth test, the paint on the field changed as follows:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值