QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#18452. 連接電纜

统计

最近,RUN 被要求連接 KAIST 中 $N$ 個區域之間的所有電纜。

我們將這些區域視為二維平面上的區域。每個區域的邊界是一個四邊形,其中兩條邊平行於 $x$ 軸,另外兩條邊平行於 $y$ 軸。換句話說,每個區域都有一個矩形邊界,以 $(x_1^i, y_1^i)$ 為左下角,$(x_2^i, y_2^i)$ 為右上角。這些區域可能會重疊。

由於安全問題,電纜必須沿著 $x$ 軸或 $y$ 軸鋪設。因此,從 $(x_1, y_1)$ 到 $(x_2, y_2)$ 鋪設電纜的成本為 $|x_1 - x_2| + |y_1 - y_2|$ 韓元。

連接兩個區域 $A$ 和 $B$ 的電纜應連接兩個點,每個區域各取一點。

請找出連接所有 $\binom{N}{2}$ 對區域之間電纜的最小總成本。

注意,必須為所有 $\binom{N}{2}$ 對區域鋪設電纜。這意味著,例如,即使一條電纜的兩個端點屬於多於一對的區域,我們也不會將其視為連接了所有這些區域對。

由於答案可能很大,請輸出其對 $998\,244\,353$ 取模後的結果。可以證明答案總是一個非負整數。

輸入格式

第一行包含一個整數 $N$。

接下來的 $N$ 行中,第 $i$ 行包含四個以空格分隔的整數 $x_1^i, y_1^i, x_2^i$ 和 $y_2^i$,分別表示代表第 $i$ 個區域的矩形左下角和右上角的位置。

輸出格式

輸出一個整數,代表鋪設所有電纜的最小總成本(單位為韓元),並對 $998\,244\,353$ 取模。$998\,244\,353 = 119 \times 2^{23} + 1$ 是一個質數。

資料範圍

  • $2 \le N \le 300\,000$
  • $0 \le x_1^i < x_2^i \le 998\,244\,352$ ($1 \le i \le N$)
  • $0 \le y_1^i < y_2^i \le 998\,244\,352$ ($1 \le i \le N$)

範例

範例 1

輸入

3
1 7 2 9
3 2 8 4
4 3 8 5

輸出

8

範例 2

輸入

4
0 1 2 3
1 0 3 2
3 4 5 6
4 3 6 5

輸出

8

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.