No.1505 Zero-Product Ranges
タグ : / 解いたユーザー数 254
作問者 :
kichi2004_
👑 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もしくは右上の雲マークをクリックしてアカウントを作成してください。