#P17182. [ICPC 2017 Hong Kong R] Black and White

[ICPC 2017 Hong Kong R] Black and White

Problem Description

Consider a square map with N×NN \times N cells. We indicate the coordinate of a cell by (i,j)(i,j), where 1i,jN1 \le i,j \le N. Each cell has a color either white or black. The color of each cell is initialized to white. The map supports the operation $\text{flip}([x_{low}, x_{high}], [y_{low}, y_{high}])$, which flips the color of each cell in the rectangle [xlow,xhigh]×[ylow,yhigh][x_{low}, x_{high}] \times [y_{low}, y_{high}]. Given a sequence of flip operations, our problem is to count the number of black cells in the final map. We illustrate this in the following example. Figure (a) shows the initial map. Next, we call flip([2,4],[1,3])\text{flip}([2,4],[1,3]) and obtain Figure (b). Then, we call flip([1,5],[3,5])\text{flip}([1, 5], [3, 5]) and obtain Figure (c). This map contains 1818 black cells.

:::align{center} :::

Input Format

The first line contains the number of test cases TT (T10T \leq 10). Each test case begins with a line containing two integers NN and KK (1<N,K<100001 < N,K < 10000), where NN is the parameter of the map size and KK is the number of flip operations. Each subsequent line corresponds to a flip operation, with four integers: xlow,xhigh,ylow,yhighx_{low}, x_{high}, y_{low}, y_{high}.

Output Format

For each test case, output the answer in a line.

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