#P12374. Nested Summation over Subarrays
Nested Summation over Subarrays
Nested Summation over Subarrays
Given a sequence a of length n, consider every contiguous subarray (interval) [l, r] of a. For a subarray of length m = r-l+1, define its value as follows:
If there exists any index k (with 1 ≤ k ≤ m) such that k > a[l+k-1], then the value of the subarray is 0. Otherwise, the value is given by the nested summation
$$S_{l,r} = \sum_{i_1=1}^{a_l}\sum_{i_2=2}^{a_{l+1}}\cdots\sum_{i_m=m}^{a_r} \Bigl(i_1+i_2+\cdots+i_m\Bigr). $$The answer to the problem is the sum of Sl,r over all subarrays [l, r] modulo 998244353.
inputFormat
The first line contains an integer n — the length of the sequence.
The second line contains n space-separated integers representing the sequence a.
outputFormat
Print a single integer — the sum of the values of all subarrays computed as described above, taken modulo 998244353.
sample
1
1
1
</p>