問題一覧 > 通常問題

No.1505 Zero-Product Ranges

レベル : / AI推定難易度 : 208 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 254
作問者 : oliverx3 / テスター : kichi2004_ 👑 qand yuto1115
お気に入りにしたユーザー ProblemId : 6129 / 自分の提出
問題文最終更新日: 2021-05-14 11:30:21
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
yukicoder contest 295 (順位表) の他の問題:

Problem Statement

You are given a sequence $A$ of length $N$ consisting of $0$ and $1$. The $i\ (1\leq i \leq N)$-th element of the sequence is $A_i$.

Find the number of pairs $(l,\ r)\ (1 \leq l \leq r \leq N)$ such that $\displaystyle \prod_{i=l}^{r}A_i = 0$.

Here,
$\displaystyle \prod_{i=l}^{r}A_i\ =\ A_l \times A_{l+1} \times \cdots \times A_{r}$
.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $A_i = 0,\ 1\ (1 \leq i \leq N)$
  • All inputs are integers.

Input

$N$
$A_1\ A_2\ \cdots \ A_N$

Output

Output the answer, followed by a newline.

Sample

Sample 1
Input
3
1 0 1
Output
4

The pairs satisfying the condition are $(l,\ r) = (1,\ 2),\ (1,\ 3),\ (2,\ 2),\ (2,\ 3)$, for a total of $4$ pairs.

Sample 2
Input
5
1 1 1 1 1
Output
0

There may be no pairs satisfying the condition.

Sample 3
Input
10
1 1 0 1 1 1 0 0 1 1
Output
43

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