#P15622. [ICPC 2022 Jakarta R] The Only Mode

[ICPC 2022 Jakarta R] The Only Mode

题目描述

You are given an array of integers AA of size NN (indexed from 11 to NN) where AiA_i is either 00, 11, 22, or 33. A subarray l,r\langle l, r \rangle of AA is defined as [Al,Al+1,,Ar][A_l, A_{l+1}, \cdots, A_r], and its size is rl+1r - l + 1.

A value xx is the only mode of a subarray l,r\langle l, r \rangle if and only if xx appears strictly more often than other values in subarray l,r\langle l, r \rangle.

Your task in this problem is to find, for each x{0,1,2,3}x \in \{0, 1, 2, 3\}, the size of the longest subarray of AA such that xx is the only mode of that subarray, or determine if xx cannot be the only mode in any subarray.

输入格式

Input begins with an integer NN (1N1000001 \leq N \leq 100\,000) representing the size of array AA. The next line contains NN integers AiA_i (Ai{0,1,2,3}A_i \in \{0, 1, 2, 3\}).

输出格式

Output four space-separated integers in a single line. Each integer represents the answer where xx is 00, 11, 22, and 33, respectively. For each value of xx, if there exists a subarray such that xx is the only mode in that subarray, then output the size of the longest subarray; otherwise, output 00.

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 00 is the only mode is 3,6\langle 3, 6 \rangle of length 44, i.e. [2,0,3,0][2, 0, 3, 0].
  • The longest subarray such that 11 is the only mode is 1,1\langle 1, 1 \rangle of length 11, i.e. [1][1].
  • The longest subarray such that 22 is the only mode is 1,5\langle 1, 5 \rangle of length 55, i.e. [1,2,2,0,3][1, 2, 2, 0, 3].
  • The longest subarray such that 33 is the only mode is 5,7\langle 5, 7 \rangle of length 33, i.e. [3,0,3][3, 0, 3].

Explanation for the sample input/output #2

  • The longest subarray such that 00 is the only mode is 1,4\langle 1, 4 \rangle or 2,5\langle 2, 5 \rangle.
  • The longest subarray such that 11 is the only mode is 3,11\langle 3, 11 \rangle.
  • The longest subarray such that 22 is the only mode is 1,1\langle 1, 1 \rangle, 5,5\langle 5, 5 \rangle, or 9,9\langle 9, 9 \rangle.
  • The longest subarray such that 33 is the only mode is 4,12\langle 4, 12 \rangle.

Explanation for the sample input/output #3

The longest subarray such that 00 or 22 is the only mode contains only a single element by itself; on the other hand, there is no subarray such that 11 or 33 is the only mode.