No.3746 Swap and LIS
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もしくは右上の雲マークをクリックしてアカウントを作成してください。