問題一覧 > 通常問題

No.956 Number of Unbalanced

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 32
作問者 : kroton / テスター : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 3688 / 自分の提出
問題文最終更新日: 2019-12-19 00:05:16
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2019 (順位表) の他の問題:

Problem Statement

For a non-empty integer sequence $X$, if a majority of the elements of $X$ are the same number, then $X$ is called unbalanced.

Examples of unbalanced sequences: $\{1\}$, $\{1, 2, 1\}$, $\{1, 2, 2, 2\}$

Given an integer sequence $A$, count the number of non-empty contiguous subsequences of $A$ that are unbalanced.
Here, subsequences taken from different positions are counted separately, even if they are the same as sequences.

Input

$N$
$A_{1}$ $A_{2}$ $\cdots$ $A_{N}$

All inputs are given as integers.

  • $ 1 \leq N \leq 10^5 $
  • $ 1 \leq A_{i} \leq 10^5 $

Output

Print a newline at the end.

Sample

Sample 1
Input
6
1 2 2 3 2 3
Output
14

There are the following 14 subsequences.

$\{1\} ,\{1,2,2\} ,\{1,2,2,3,2\}$

$\{2\} ,\{2,2\} ,\{2,2,3\} ,\{2,2,3,2\} ,\{2,2,3,2,3\}$

$\{2\} ,\{2,3,2\}$

$\{3\} ,\{3,2,3\}$

$\{2\}$

$\{3\}$

Sample 2
Input
1
1
Output
1
Sample 3
Input
10
1 1 2 4 2 4 3 4 4 2
Output
25
Sample 4
Input
10
1 7 7 7 3 9 3 1 4 1
Output
21
Sample 5
Input
10
1 1 1 1 1 1 1 1 1 1
Output
55
Sample 6
Input
10
1 2 3 4 5 6 7 8 9 10
Output
10

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。