No.2956 Substitute with Average
Problem Statement
You are given an integer sequence $(A_1,\cdots, A_N)$ with $N$ terms. Find the number of distinct sequences that can be obtained by performing the following operation $1$ time.
・ Choose a pair of integers $(L, R)$ such that $1\leq L \leq R \leq N$. Replace $A_L, A_{L + 1}, \cdots, A_R$ with their average. That is, for $i = L, L + 1, \dots, R$, simultaneously replace $A_i$ with $\dfrac{A_L + \cdots + A_R}{R - L + 1}$.
Constraints
・ $1\leq N \leq 10^5$
・ $1\leq A_i \leq 30$ $(1\leq i \leq N)$
・All input values are integers.
Input
$N$ $A_1$ $A_2$ $\cdots$ $A_N$
Output
Find the number of sequences that can be obtained and print it on $1$ line.
Sample
Sample 1
Input
3 2 4 6
Output
4
$4$ different sequences can be obtained by the operation. The obtainable sequences and specific ways to obtain them are listed below.
・$(2, 4, 6)$ is obtained by performing the operation with $(L, R) = (1, 1)$.
・$(3, 3, 6)$ is obtained by performing the operation with $(L, R) = (1, 2)$.
・$(2, 5, 5)$ is obtained by performing the operation with $(L, R) = (2, 3)$.
・$(4, 4, 4)$ is obtained by performing the operation with $(L, R) = (1, 3)$.
The way to obtain each sequence is not necessarily unique.
Sample 2
Input
4 5 5 5 5
Output
1
Sample 3
Input
2 1 2
Output
2
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
startcpp
hamamu