#P2692. 覆盖

覆盖

Description

The playground can be viewed as an NN-by-MM grid of cells. As shown in Figure (1), this is a 44-by-55 grid. Each boy is responsible for sweeping some consecutive rows, and each girl is responsible for sweeping some consecutive columns. For example, suppose there are two boys: the first boy is responsible for rows 1,21, 2, and the second boy is responsible for row 44, shown in blue in Figure (2). The swept regions may overlap. For instance, suppose there are also two girls: the first girl is responsible for columns 3,43, 4, and the second girl is responsible for columns 4,54, 5, shown in red in Figure (3). From Figure (3), it is easy to see that the number of colored cells is 18, i.e., these four students have swept a total of 18 cells.

The teacher asks WSR to quickly compute, given the cleaning plan data, how many cells have been swept in total.

Input Format

The first line contains 44 positive integers: N,M,B,GN, M, B, G. Here, NN is the number of rows, MM is the number of columns, BB is the number of boys, and GG is the number of girls.

The next BB lines each contain two integers x,yx, y. Each line indicates that a boy is responsible for rows xx through yy inclusive (a total of yx+1y - x + 1 rows), with the guarantee that 1xyN1 \le x \le y \le N.

Then the next GG lines each contain two integers x,yx, y. Each line indicates that a girl is responsible for columns xx through yy inclusive (a total of yx+1y - x + 1 columns), with the guarantee that 1xyM1 \le x \le y \le M.

Output Format

Output a single integer, the swept area (i.e., the total number of cells).

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

Hint

If you are not sure, try drawing a diagram yourself.

Constraints:

  • For 80%80\% of the testdata, 1N,M,B,G1021 \le N,M,B,G \le 10^2.
  • For 100%100\% of the testdata, 1N,M,B,G5×103 1 \le N,M,B,G \le 5 \times 10^3.

Translated by ChatGPT 5