P30019 [洛谷] [COCI2022-2023#2] Lampice
提高
题目描述

Problem Description

Teo's balcony is a rectangular platform with dimensions \( n+1 \) by \( m+1 \), containing \( 2k \) colored lamps. The colors of these lamps are represented by numbers from \( 1 \) to \( k \). There are exactly two lamps of each color, and their coordinates are positive integers.

Teo considers a region on the balcony to be good if and only if:

  • The region is a rectangle with sides parallel to the sides of the balcony.
  • For each color, both lamps of that color are either inside the region or outside the region.
  • The coordinates of the top-left and bottom-right corners of the region are integers.
  • The dimensions of the region are at least \( 2 \) in both length and width.

Teo wants you to determine how many such good regions exist on his balcony.

Note: The bottom-left corner is at coordinates \( (0,0) \) and the top-right corner is at coordinates \( (n,m) \).

Input Format

The first line contains three integers \( n \), \( m \), and \( k \) (\( 1 \le n \le 150, 1 \le m \le 1000, 0 \le k \le 200000 \)), representing the length and width of the balcony, and the number of colors of the lamps, respectively.

The next \( k \) lines each contain four integers \( x_1 \), \( y_1 \), \( x_2 \), \( y_2 \), where the \( i \)-th line represents the coordinates of the two lamps of color \( i \).

Output Format

Output a single integer, the number of good regions.

Sample Input and Output

Sample Input #1

2 2 1
0 0 1 2

Sample Output #1

3

Sample Input #2

3 3 0

Sample Output #2

36

Sample Input #3

3 3 5
0 0 0 0
0 0 1 3
0 0 3 1
1 3 3 1
1 3 3 1

Sample Output #3

7

Notes/Hints

Subtask Points Special Conditions
1 26 For each color, \( x_1 = y_1 = 0 \)
2 12 \( n, m \le 10 \), \( k \le 1000 \)
3 35 \( m \le 150 \)
4 37 None

This problem is worth a total of 110 points.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 1 0 0 1 2
样例输出
3