The Only Mode

시간 제한2초메모리 제한1024 MB

요약
0부터 3까지 각 값에 대해, 그 값이 다른 모든 값보다 더 많이 등장하는 가장 긴 부분 배열의 길이를 구한다.
난이도

보통10점 중 7점

유형
누적 합, 완전 탐색, 해시맵, 그리디
정답자
아직 제출이 없습니다

문제

You are given an array of integers AA of size NN (indexed from 11 to NN) where A_iA\_i is either 00, 11, 22, or 33.

A subarray ⟨l,r⟩⟨l, r⟩ of AA is defined as \[A_l,A_l+1,⋯ ,A_r]\[A\_l , A\_{l+1}, \cdots , A\_r], and its size is r−l+1r - l + 1.

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

Your task in this problem is to find, for each x∈0,1,2,3x ∈ \\{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 (1≤N≤100,0001 ≤ N ≤ 100\\, 000) representing the size of array AA. The next line contains NN integers A_iA\_i (A_i∈0,1,2,3A\_i ∈ \\{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.

예제4

  1. 예제 1

    입력
    7
    1 2 2 0 3 0 3
    
    예상 출력
    4 1 5 3
    
  2. 예제 2

    입력
    12
    2 0 1 0 2 1 1 0 2 3 3 3
    
    예상 출력
    4 9 1 9
    
  3. 예제 3

    입력
    2
    0 2
    
    예상 출력
    1 0 1 0
    
  4. 예제 4

    입력
    12
    3 0 2 2 1 0 2 1 3 3 2 3
    
    예상 출력
    1 5 11 8