#P15622. [ICPC 2022 Jakarta R] The Only Mode
[ICPC 2022 Jakarta R] The Only Mode
题目描述
You are given an array of integers of size (indexed from to ) where is either , , , or . A subarray of is defined as , and its size is .
A value is the only mode of a subarray if and only if appears strictly more often than other values in subarray .
Your task in this problem is to find, for each , the size of the longest subarray of such that is the only mode of that subarray, or determine if cannot be the only mode in any subarray.
输入格式
Input begins with an integer () representing the size of array . The next line contains integers ().
输出格式
Output four space-separated integers in a single line. Each integer represents the answer where is , , , and , respectively. For each value of , if there exists a subarray such that is the only mode in that subarray, then output the size of the longest subarray; otherwise, output .
7
1 2 2 0 3 0 3
4 1 5 3
12
2 0 1 0 2 1 1 0 2 3 3 3
4 9 1 9
2
0 2
1 0 1 0
12
3 0 2 2 1 0 2 1 3 3 2 3
1 5 11 8
提示
Explanation for the sample input/output #1
- The longest subarray such that is the only mode is of length , i.e. .
- The longest subarray such that is the only mode is of length , i.e. .
- The longest subarray such that is the only mode is of length , i.e. .
- The longest subarray such that is the only mode is of length , i.e. .
Explanation for the sample input/output #2
- The longest subarray such that is the only mode is or .
- The longest subarray such that is the only mode is .
- The longest subarray such that is the only mode is , , or .
- The longest subarray such that is the only mode is .
Explanation for the sample input/output #3
The longest subarray such that or is the only mode contains only a single element by itself; on the other hand, there is no subarray such that or is the only mode.