QOJ.ac

QOJ

時間限制: 6.0 s 記憶體限制: 2048 MB

#22863. 空交集

统计

畀定兩個整數序列 $A = (A_1, \dots, A_N)$ 同 $B = (B_1, \dots, B_N)$,以及兩個正整數序列 $V = (V_1, \dots, V_N)$ 同 $W = (W_1, \dots, W_N)$。呢四個序列嘅長度都係 $N$。

請揀兩個(可以係空嘅)下標區間:$[L, R)$ 對應 $A$,而 $[U, D)$ 對應 $B$。呢度 $L, R, U, D$ 係滿足 $1 \le L \le R \le N + 1$ 同埋 $1 \le U \le D \le N + 1$ 嘅整數。

設 $X$ 同 $Y$ 分別係呢兩個區間入面出現嘅數值集合:

$$ \begin{aligned} X &= \{A_i \mid L \le i < R\}, \\ Y &= \{B_j \mid U \le j < D\}. \end{aligned} $$

所揀嘅區間必須滿足 $X \cap Y = \emptyset$。換句話講,唔可以有任何數值同時喺兩個區間入面出現。

如果 $L = R$,咁 $A$ 嘅區間就係空嘅,而且 $X = \emptyset$。同樣道理,如果 $U = D$,咁 $B$ 嘅區間就係空嘅,而且 $Y = \emptyset$。

所揀兩個區間嘅得分係

$$ \sum_{i=L}^{R-1} V_i + \sum_{j=U}^{D-1} W_j. $$

請喺所有合法嘅選擇之中,搵出可能嘅最大得分。

輸入格式

輸入包含一或多個測試用例。輸入嘅第一行包含一個整數 $T$($1 \le T \le 10^4$),代表測試用例嘅數量。跟住係 $T$ 個測試用例嘅描述,每個測試用例嘅格式如下:

$$ \begin{aligned} &N \\ &A_1 \ A_2 \ \dots \ A_N \\ &B_1 \ B_2 \ \dots \ B_N \\ &V_1 \ V_2 \ \dots \ V_N \\ &W_1 \ W_2 \ \dots \ W_N \end{aligned} $$

第一行包含一個整數 $N$,代表四個序列嘅共同長度($1 \le N \le 2 \times 10^5$)。

跟住嘅四行每行包含 $N$ 個整數,分別描述序列 $A$、$B$、$V$ 同 $W$。

整數 $A_i$ 同 $B_i$ 滿足 $1 \le A_i, B_i \le N$(對於每個 $i$,$1 \le i \le N$)。

整數 $V_i$ 同 $W_i$ 滿足 $1 \le V_i, W_i \le 10^9$(對於每個 $i$,$1 \le i \le N$)。

所有測試用例入面 $N$ 嘅總和唔超過 $6 \times 10^5$。

輸出格式

輸出 $T$ 行。第 $i$ 行應該包含第 $i$ 個測試用例嘅最大可能得分。

範例

輸入格式 1

4
3
1 2 3
3 2 1
3 4 5
6 2 1
3
1 1 1
1 1 1
2 3 4
5 5 5
4
1 2 1 3
4 2 4 3
5 6 5 1
4 10 4 10
5
3 1 2 4 3
1 1 2 2 4
1 3 3 2 1
2 2 3 1 1

輸出格式 1

13
15
33
11

說明

喺第一個測試用例入面,我哋可以揀區間 $[1, 3)$(屬於 $A$)同埋區間 $[1, 2)$(屬於 $B$)。準確啲講,我哋可以設 $L = 1$、$R = 3$、$U = 1$ 同 $D = 2$。佢哋嘅數值集合分別係 $\{1, 2\}$ 同 $\{3\}$,互不相交。得分係

$$ V_1 + V_2 + W_1 = 3 + 4 + 6 = 13, $$

呢個就係最大可能得分。

喺第二個測試用例入面,我哋可以揀 $A$ 嘅空區間同埋整個區間 $[1, 4)$(屬於 $B$)。準確啲講,即係 $L = 2$、$R = 2$、$U = 1$ 同 $D = 4$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2891EditorialOpensolnullptr_qwqView

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.