2026牛客国庆集训派对day6
H
Rectangle Intersection
牛客竞赛
未评级
原题
← GI →

Rectangle Intersection官方中文

题目描述

官方中文

In an $n$ by $m$ grid, there are $k$ rectangles, each described by a tuple $(x_1, y_1, x_2, y_2)$ ($1 \leq x_1 \leq x_2 \leq n, 1 \leq y_1 \leq y_2 \leq m$), indicating that the rectangle covers all cells from row $x_1$ to $x_2$ and from column $y_1$ to $y_2$. For a collection of rectangles, their intersection is defined as the set of all cells that are covered by all these rectangles simultaneously. If no cell is covered by all these rectangles simultaneously, we consider the intersection of these rectangles to be empty. Now, you need to select some rectangles from the given $k$ rectangles such that their intersection is non-empty, and you should minimize the number of cells contained in the intersection of these rectangles. You only need to output the number of cells contained in the intersection of these rectangles.官方中文

输入格式

官方中文

The first line of input contains three positive integers $n$, $m$, and $k$ ($1 \leq n, m \leq 2000, 1 \leq k \leq 10^6$), representing the number of rows and columns in the grid, and the number of rectangles, respectively.官方中文

Then $k$ lines follow, each containing a description of one rectangle. Each rectangle's description consists of $4$ numbers $x_1, y_1, x_2, y_2$ ($1 \leq x_1 \leq x_2 \leq n, 1 \leq y_1 \leq y_2 \leq m$), indicating that the rectangle covers all cells from row $x_1$ to $x_2$ and from column $y_1$ to $y_2$.官方中文

输出格式

官方中文

Output a positive integer in a line, denoting the answer.
官方中文

样例

Input #1
6 4 2
2 2 4 3
3 2 5 3
Output #1
4
Input #2
19 19 4
1 9 10 9
9 10 9 19
11 1 11 10
10 11 19 11
Output #2
10
Input #3
7 7 2
1 1 7 7
2 2 6 6
Output #3
25
Input #4
5 5 2
1 1 4 4
2 2 5 5
Output #4
9
题目信息
题号
nc140734ph
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 牛客竞赛 及出题人所有;中文翻译由 AI 生成(官方原文),如有出入请以原文为准。