CF2227D.Palindromex
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yousef has given you an array a of 2n integers. Every integer x∈[0,n−1] appears exactly twice in the array.
Your task is to find a subarray al,al+1,…,ar that is a palindrome∗ such that its mex(al,al+1,…,ar)† is maximized. Output this maximum possible value.
∗A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
†The mex (minimum excludant) of an array of integers is defined as the smallest non-negative integer which does not occur in the array. For example:
- The mex of [2,2,1] is 0, because 0 does not belong to the array.
- The mex of [3,1,0,1] is 2, because 0 and 1 belong to the array, but 2 does not.
- The mex of [0,3,1,2] is 4, because 0, 1, 2 and 3 belong to the array, but 4 does not.
优素福给了你一个包含 2n 个整数的数组 a。对于每个整数 x∈[0,n−1],它在数组中恰好出现两次。
你的任务是找出一个回文子数组 al,al+1,…,ar,使得其 mex(al,al+1,…,ar)† 最大化。请输出这个可能的最大值。
∗ 回文是指正读与反读都相同的字符串,例如字符串 "z"、"aaa"、"aba"、"abccba" 都是回文,但字符串 "codeforces"、"reality"、"ab" 不是。
† 一个整数数组的 mex(最小未出现值)定义为不在该数组中出现的最小非负整数。例如:
- [2,2,1] 的 mex 是 0,因为 0 不在数组中;
- [3,1,0,1] 的 mex 是 2,因为 0 和 1 在数组中,但 2 不在;
- [0,3,1,2] 的 mex 是 4,因为 0、1、2 和 3 都在数组中,但 4 不在。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤105).
The second line of each test case contains 2n integers a1,a2,…,a2n (0≤ai≤n−1). It is guaranteed that every integer in the range [0,n−1] appears exactly twice.
It is guaranteed that the sum of 2n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105)。
每个测试用例的第二行包含 2n 个整数 a1,a2,…,a2n(0≤ai≤n−1)。保证区间 [0,n−1] 中的每个整数恰好出现两次。
保证所有测试用例中 2n 的总和不超过 2⋅105。
输出格式
For each test case, output a single integer — the maximum mex of any palindromic subarray.
对于每个测试用例,输出一个整数——任意回文子数组的最大 mex 值。
输入输出样例
输入#1
6 4 1 2 0 3 3 0 2 1 2 0 1 0 1 2 1 1 0 0 3 2 0 2 1 1 0 4 0 1 3 0 3 1 2 2 3 0 1 2 1 0 2
输出#1
4 2 1 1 2 3
说明/提示
In the first test case, the only optimal subarray to choose is a[1,8]=[1,2,0,3,3,0,2,1], which is palindromic and has a mex of 4.
In the second test case, one of the optimal subarrays to choose is a[2,4]=[1,0,1], which is palindromic and has a mex of 2.
In the third test case, we can choose a[3,3]=[0], which is palindromic and has a mex of 1. No other palindromic subarray has a mex greater than 1.
在第一个测试用例中,唯一最优的可选子数组是 a[1,8]=[1,2,0,3,3,0,2,1],该子数组是回文的,且其 mex 值为 4。
在第二个测试用例中,一个最优的可选子数组是 a[2,4]=[1,0,1],该子数组是回文的,且其 mex 值为 2。
在第三个测试用例中,我们可以选择 a[3,3]=[0],该子数组是回文的,且其 mex 值为 1。不存在其他回文子数组的 mex 值大于 1。
输入解题思路,AI测评打分。不知道怎么写?