QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 2048 MB 總分: 100

#5543. 唯一的众数

统计

给定一个大小为 $N$ 的整数数组 $A$(下标从 $1$ 到 $N$),其中 $A_i$ 为 $0, 1, 2$ 或 $3$。

数组 $A$ 的子数组 $\langle l, r \rangle$ 定义为 $[A_l, A_{l+1}, \dots, A_r]$,其长度为 $r - l + 1$。

当且仅当值 $x$ 在子数组 $\langle l, r \rangle$ 中出现的次数严格多于其他值时,称 $x$ 为该子数组的唯一众数。

你的任务是对于每个 $x \in \{0, 1, 2, 3\}$,求出 $A$ 中以 $x$ 为唯一众数的最长子数组的长度;如果 $x$ 在任何子数组中都不能成为唯一众数,则输出 $0$。

输入格式

输入的第一行包含一个整数 $N$ ($1 \le N \le 100\,000$),表示数组 $A$ 的大小。下一行包含 $N$ 个整数 $A_i$ ($A_i \in \{0, 1, 2, 3\}$)。

输出格式

在一行中输出四个空格分隔的整数,分别代表 $x$ 为 $0, 1, 2, 3$ 时的答案。对于每个 $x$,如果存在以 $x$ 为唯一众数的子数组,则输出最长子数组的长度;否则输出 $0$。

样例

输入 1

7
1 2 2 0 3 0 3

输出 1

4 1 5 3

说明 1

  • $0$ 为唯一众数的最长子数组是 $\langle 3, 6 \rangle$,长度为 $4$,即 $[2, 0, 3, 0]$。
  • $1$ 为唯一众数的最长子数组是 $\langle 1, 1 \rangle$,长度为 $1$,即 $[1]$。
  • $2$ 为唯一众数的最长子数组是 $\langle 1, 5 \rangle$,长度为 $5$,即 $[1, 2, 2, 0, 3]$。
  • $3$ 为唯一众数的最长子数组是 $\langle 5, 7 \rangle$,长度为 $3$,即 $[3, 0, 3]$。

输入 2

12
2 0 1 0 2 1 1 0 2 3 3 3

输出 2

4 9 1 9

说明 2

  • $0$ 为唯一众数的最长子数组是 $\langle 1, 4 \rangle$ 或 $\langle 2, 5 \rangle$。
  • $1$ 为唯一众数的最长子数组是 $\langle 3, 11 \rangle$。
  • $2$ 为唯一众数的最长子数组是 $\langle 1, 1 \rangle, \langle 5, 5 \rangle$ 或 $\langle 9, 9 \rangle$。
  • $3$ 为唯一众数的最长子数组是 $\langle 4, 12 \rangle$。

输入 3

2
0 2

输出 3

1 0 1 0

说明 3

$0$ 或 $2$ 为唯一众数的最长子数组仅包含单个元素;另一方面,不存在以 $1$ 或 $3$ 为唯一众数的子数组。

输入 4

12
3 0 2 2 1 0 2 1 3 3 2 3

输出 4

1 5 11 8

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.