CF1831B Array merging
题目描述
给定两个长度为 $n$ 的数组 $a$ 和 $b$。
猫猫让你合并这些数组,形成另一个长度为 $2n$ 的数组 $c$。你需要找到所有 $c$ 中元素值相同的子串长度的最大值。
合并过程是:每次选择任一非空数组中的第一个元素,将其添加到 $c$ 的末尾后从原数组中删除,这样的操作进行 $2n$ 次,直到两个数组都为空为止。
输入格式
第一行包含整数 $t$,表示测试数据的数量。
对于每组测试数据:
第一行一个整数 $n$,表示数组 $a$ 和 $b$ 的长度。
第二行 $n$ 个整数 $a_1,a_2,\dots,a_n$,表示数组 $a$ 的元素。
第三行 $n$ 个整数 $b_1,b_2,\dots,b_n$,表示数组 $b$ 的元素。
保证所有测试数据中 $n$ 的总和不超过 $ 2 \cdot 10^5 $。
输出格式
对于每个测试数据,输出跨所有合并数组 $c$ 的相等值的最大子数组的长度。
说明/提示
In the first test case, we can only make $ c=[2,2] $ , thus the answer is $ 2 $ .
In the second test case, since all values are distinct, the answer must be $ 1 $ .
In the third test case, the arrays $ c $ we can make are $ [1,2,1,2] $ , $ [1,2,2,1] $ , $ [2,1,1,2] $ , $ [2,1,2,1] $ . We can see that the answer is $ 2 $ when we choose $ c=[1,2,2,1] $ .