#abc381d. D - 1122 Substring
D - 1122 Substring
当前没有测试数据。
Score : points
问题陈述
一个正整数序列 (可能为空)被称为1122序列,当且仅当它满足以下三个条件:(1122序列的定义与问题F中的定义相同。)
- 是偶数。这里, 表示 的长度。
- 对于每个满足 的整数 , 和 相等。
- 每个正整数在 中要么不出现,要么恰好出现两次。也就是说, 中包含的每个正整数在 中恰好出现两次。
给定一个由正整数组成的长度为 的序列 ,请打印出 的一个**(连续的)子数组**的最大长度,该子数组是一个1122序列。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
A sequence of positive integers (possibly empty) is called a 1122 sequence if and only if it satisfies all of the following three conditions: (The definition of a 1122 sequence is the same as in Problem F.)
- is even. Here, denotes the length of .
- For each integer satisfying , and are equal.
- Each positive integer appears in either not at all or exactly twice. That is, every positive integer contained in appears exactly twice in .
Given a sequence of length consisting of positive integers, print the maximum length of a (contiguous) subarray of that is a 1122 sequence.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum length of a (contiguous) subarray of that is a 1122 sequence.
Sample Input 1
8
2 3 1 1 2 2 1 1
Sample Output 1
4
For example, taking the subarray from the -rd to -th elements of , we get , which is a 1122 sequence of length .
There is no longer (contiguous) subarray that satisfies the conditions for a 1122 sequence, so the answer is .
Sample Input 2
3
1 2 2
Sample Output 2
2
Sample Input 3
1
1
Sample Output 3
0
Note that a sequence of length also satisfies the conditions for a 1122 sequence.