CF1781E.Rectangle Shrinking

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You have a rectangular grid of height 22 and width 10910^9 consisting of unit cells. There are nn rectangles placed on this grid, and the borders of these rectangles pass along cell borders. The ii-th rectangle covers all cells in rows from uiu_i to did_i inclusive and columns from lil_i to rir_i inclusive (1≤ui≤di≤21 \le u_i \le d_i \le 2; 1≤li≤ri≤1091 \le l_i \le r_i \le 10^9). The initial rectangles can intersect, be nested, and coincide arbitrarily.

You should either remove each rectangle, or replace it with any of its non-empty subrectangles. In the latter case, the new subrectangle must lie inside the initial rectangle, and its borders must still pass along cell borders. In particular, it is allowed for the subrectangle to be equal to the initial rectangle.

After that replacement, no two (non-removed) rectangles are allowed to have common cells, and the total area covered with the new rectangles must be as large as possible.

Illustration for the first test case. The initial rectangles are given at the top, the new rectangles are given at the bottom. Rectangle number 44 is removed.

你有一个高度为 22、宽度为 10910^9 的矩形网格,由单位格子构成。该网格上放置了 nn 个矩形,这些矩形的边界均与格子边界重合。第 ii 个矩形覆盖所有行号在 uiu_i 到 did_i(含端点)之间、列号在 lil_i 到 rir_i(含端点)之间的格子(其中 1≤ui≤di≤21 \le u_i \le d_i \le 2;1≤li≤ri≤1091 \le l_i \le r_i \le 10^9)。初始矩形可以任意相交、嵌套或完全重合。

你需要对每个矩形执行以下两种操作之一:

  • 将其移除;
  • 或将其替换为它的任意一个非空子矩形。该子矩形必须完全位于原矩形内部,且其边界仍需与格子边界重合。特别地,允许子矩形与原矩形完全相同。

完成上述操作后,任意两个未被移除的矩形不得覆盖任何公共格子,且所有新矩形所覆盖的总格子数应尽可能大。

第一个测试用例示意图。顶部为初始矩形,底部为操作后的新矩形。矩形编号 44 被移除。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of rectangles.

Each of the next nn lines contains four integers ui,li,di,riu_i, l_i, d_i, r_i (1≤ui≤di≤21 \le u_i \le d_i \le 2; 1≤li≤ri≤1091 \le l_i \le r_i \le 10^9) — the coordinates of cells located in the top-left and the bottom-right corners of the rectangle, respectively.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 矩形的数量。

接下来的 nn 行中,每行包含四个整数 ui,li,di,riu_i, l_i, d_i, r_i(1≤ui≤di≤21 \le u_i \le d_i \le 2;1≤li≤ri≤1091 \le l_i \le r_i \le 10^9),分别表示该矩形左上角与右下角单元格的坐标。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, first print an integer ss — the largest possible covered by new rectangles area. Then print nn lines with your solution to cover this area.

In the ii-th of these lines print four integers ui′,li′,di′,ri′u'_i, l'_i, d'_i, r'_i. If you remove the ii-th rectangle, print ui′=li′=di′=ri′=0u'_i = l'_i = d'_i = r'_i = 0. Otherwise, these numbers denote the new coordinates of the top-left and the bottom-right corners of the ii-th rectangle, satisfying ui≤ui′≤di′≤diu_i \le u'_i \le d'_i \le d_i; li≤li′≤ri′≤ril_i \le l'_i \le r'_i \le r_i.

If there are multiple solutions, print any.

对于每个测试用例,首先输出一个整数 ss —— 新矩形所能覆盖的最大面积。然后输出 nn 行,表示达到该最大覆盖面积的一种方案。

在这些行中的第 ii 行,输出四个整数 ui′,li′,di′,ri′u'_i, l'_i, d'_i, r'_i。若你选择移除第 ii 个矩形,则输出 ui′=li′=di′=ri′=0u'_i = l'_i = d'_i = r'_i = 0;否则,这四个数表示第 ii 个矩形调整后的新坐标,其中 (ui′,li′)(u'_i, l'_i) 和 (di′,ri′)(d'_i, r'_i) 分别为其左上角和右下角顶点,且需满足约束:ui≤ui′≤di′≤diu_i \le u'_i \le d'_i \le d_i 以及 li≤li′≤ri′≤ril_i \le l'_i \le r'_i \le r_i。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    8
    5
    1 2 2 4
    2 4 2 8
    1 4 2 7
    1 2 1 2
    1 9 1 10
    2
    1 1 1 10
    1 5 1 15
    2
    1 1 1 10
    1 1 1 10
    5
    1 3 1 7
    1 3 1 8
    1 1 1 4
    1 2 1 7
    1 10 1 11
    2
    1 1 2 10
    1 5 1 8
    2
    1 5 2 10
    1 2 1 7
    2
    1 5 2 10
    2 2 2 15
    5
    2 6 2 7
    1 4 2 5
    1 5 1 9
    1 7 2 10
    1 2 1 6

    输出#1

    15
    1 2 2 4
    2 5 2 8
    1 5 1 7
    0 0 0 0
    1 9 1 10
    15
    1 1 1 10
    1 11 1 15
    10
    1 1 1 10
    0 0 0 0
    10
    0 0 0 0
    1 8 1 8
    1 1 1 4
    1 5 1 7
    1 10 1 11
    20
    1 1 2 10
    0 0 0 0
    15
    1 5 2 10
    1 2 1 4
    20
    1 5 1 10
    2 2 2 15
    16
    2 6 2 6
    2 4 2 5
    0 0 0 0
    1 7 2 10
    1 2 1 6

说明/提示

The picture in the statement illustrates the first test case.

题目描述中的图片展示了第一个测试用例。

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

首页