問題一覧 > 通常問題

No.3746 Swap and LIS

レベル : / AI推定難易度 : 2700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 13
作問者 : Naru820 / テスター : ponjuice
お気に入りにしたユーザー ProblemId : 13221 / 自分の提出
問題文最終更新日: 2026-10-31 15:08:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 515 (順位表) の他の問題:

Problem Statement

You are given integer sequences $A,B$ of length $N$. You may repeat the following operation any number of times.

  • Choose one integer $i$ satisfying $1 \le i \le N$, and swap the values of $A_i,B_i$.

Find the maximum possible value of $\text{LIS}(A) + \text{LIS}(B)$ after the operations.

Here, for an integer sequence $X$, $\text{LIS}(X)$ denotes the maximum possible length of a strictly increasing subsequence of $X$.

There are $T$ test cases in total.

Constraints

  • $1 \le T \le 2\times 10^5$
  • $2 \le N \le 2 \times 10^5$
  • $1 \le A_i,B_i \le 10^9$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$
  • All input values are integers

Input

The input is given from Standard Input in the following format. Here, $\text{case}_i$ is the $i$-th test case.

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_{T}$

Each test case is given in the following format.

$N$
$A_1 \ A_2 \ldots A_N$
$B_1 \ B_2 \ldots B_N$

Output

Output $T$ lines. On the $i$-th line, output the answer for $\text{case}_i$.

Sample

Sample 1
Input
3
3
4 2 3
1 1 6
5
8 1 6 9 2
7 5 6 2 3
7
7 9 2 7 8 3 4
2 1 8 3 7 7 8
Output
5
6
8

For the first test case, performing the operation only on $i = 2$ gives $A = (4,1,3),B=(1,2,6)$, and in this case $\text{LIS}(A) + \text{LIS}(B) = 5$. It can also be proved that $\text{LIS}(A) + \text{LIS}(B) = 6$ cannot be achieved no matter how the operations are performed, so the answer is $5$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。