CF1198E.Rectangle Painting 2

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a square grid of size n×nn \times n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min⁡(h,w)\min(h, w) to color a rectangle of size h×wh \times w. You are to make all cells white for minimum total cost.

The square is large, so we give it to you in a compressed way. The set of black cells is the union of mm rectangles.

有一个大小为 n×nn \times n 的正方形网格。其中部分格子被染成黑色,其余格子均为白色。在一次操作中,你可以选择某个矩形区域,并将该矩形内的所有格子染成白色。将一个大小为 h×wh \times w 的矩形染白的代价为 min⁡(h,w)\min(h, w)。你的目标是以最小总代价将所有格子染成白色。

该正方形网格规模很大,因此我们以压缩形式给出它:所有黑格子的集合是 mm 个矩形的并集。

输入格式

The first line contains two integers nn and mm (1≤n≤1091 \le n \le 10^{9}, 0≤m≤500 \le m \le 50) — the size of the square grid and the number of black rectangles.

Each of the next mm lines contains 4 integers xi1x_{i1} yi1y_{i1} xi2x_{i2} yi2y_{i2} (1≤xi1≤xi2≤n1 \le x_{i1} \le x_{i2} \le n, 1≤yi1≤yi2≤n1 \le y_{i1} \le y_{i2} \le n) — the coordinates of the bottom-left and the top-right corner cells of the ii-th black rectangle.

The rectangles may intersect.

第一行包含两个整数 nn 和 mm(1≤n≤1091 \le n \le 10^{9},0≤m≤500 \le m \le 50)—— 分别表示正方形网格的尺寸以及黑色矩形的数量。

接下来的 mm 行中,每行包含四个整数 xi1x_{i1}、yi1y_{i1}、xi2x_{i2}、yi2y_{i2}(1≤xi1≤xi2≤n1 \le x_{i1} \le x_{i2} \le n,1≤yi1≤yi2≤n1 \le y_{i1} \le y_{i2} \le n)—— 表示第 ii 个黑色矩形的左下角单元格与右上角单元格的坐标。

这些矩形可以相互相交。

输出格式

Print a single integer — the minimum total cost of painting the whole square in white.

输出一个整数——将整个正方形涂成白色的最小总代价。

输入输出样例

  • 输入#1

    10 2
    4 1 5 10
    1 4 10 5

    输出#1

    4
  • 输入#2

    7 6
    2 1 2 1
    4 2 4 3
    2 5 2 5
    2 3 5 3
    1 2 1 2
    3 2 5 3

    输出#2

    3

说明/提示

The examples and some of optimal solutions are shown on the pictures below.

示例及部分最优解如下图所示。

输入解题思路,AI测评打分。不知道怎么写?

首页