#P9737. [COCI 2022/2023 #2] Lampice

[COCI 2022/2023 #2] Lampice

Problem Description

Teo’s balcony is a rectangular platform with length n+1n+1 and width m+1m+1. There are 2k2k colored lights on it. The color of each light is represented by a number from 1∼k1 \sim k. For each color, there are exactly 22 lights, and all their coordinates are positive integers.

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

  • This region is a rectangle, and all its sides are parallel to the sides of the balcony.

  • For the two lights of each color, either both are inside the region, or both are outside the region.

  • The coordinates of the top-left corner and the bottom-right corner of the region are both integers.

  • The length and width of the region are both at least 22.

Now Teo wants you to find how many good regions there are on his balcony.

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

Input Format

The first line contains three integers nn, mm, kk (1≤n≤150,1≤m≤1000,0≤k≤2000001\le n\le150,1\le m\le1000,0\le k\le200000), representing the length and width of the balcony, and the number of light colors.

The next kk lines each contain four integers x1x_1, y1y_1, x2x_2, y2y_2. The ii-th line gives the coordinates of the two lights of color ii.

Output Format

One line containing one integer, the number of good regions.

2 2 1
0 0 1 2
3
3 3 0
36
3 3 5
0 0 0 0
0 0 1 3
0 0 3 1
1 3 3 1
1 3 3 1
7

Hint

Subtask\text{Subtask} Score Special Properties
11 2626 For each color, x1=y1=0x_1=y_1=0
22 1212 n,m≤10n,m\le10, k≤1000k\le1000
33 3535 m≤150m\le150
44 3737 None

The full score for this problem is 110110 points.

Translated by ChatGPT 5