1080C.md (4026B)
1 Source: https://codeforces.com/problemset/problem/1080/C 2 3 C. Masha and two friends 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Recently, Masha was presented with a chessboard with a height of $n$ and a width of $m$. 22 23 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). 24 25 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)$. 26 27 The chessboard is painted black and white as follows: 28 29  An example of a chessboard. 30 31 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 $(x_1,y_1,x_2,y_2)$. Then after him Denis spilled black paint on the rectangle $(x_3,y_3,x_4,y_4)$. 32 33 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). 34 35 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! 36 37 Input 38 39 The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. 40 41 Each of them is described in the following format: 42 43 The first line contains two integers $n$ and $m$ ($1 \le n,m \le 10^9$) — the size of the board. 44 45 The second line contains four integers $x_1$, $y_1$, $x_2$, $y_2$ ($1 \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. 46 47 The third line contains four integers $x_3$, $y_3$, $x_4$, $y_4$ ($1 \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. 48 49 Output 50 51 Output $t$ lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively. 52 53 Example 54 55 Input 56 57 ``` 58 5 59 2 2 60 1 1 2 2 61 1 1 2 2 62 3 4 63 2 2 3 2 64 3 1 4 3 65 1 5 66 1 1 5 1 67 3 1 5 1 68 4 4 69 1 1 4 2 70 1 3 4 4 71 3 4 72 1 2 4 2 73 2 1 3 3 74 ``` 75 76 Output 77 78 ``` 79 0 4 80 3 9 81 2 3 82 8 8 83 4 8 84 ``` 85 86 Note 87 88 Explanation for examples: 89 90 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). 91 92 In the first test, the paint on the field changed as follows: 93 94  95 96 In the second test, the paint on the field changed as follows: 97 98  99 100 In the third test, the paint on the field changed as follows: 101 102  103 104 In the fourth test, the paint on the field changed as follows: 105 106  107 108 In the fifth test, the paint on the field changed as follows: 109 110 