时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld
题目描述
Maximum Subsegment Sum is a classical problem. When Rikka first saw this problem, she was still an outsider of competitive programming, and now, she has become a problem setter of this grand event.
Therefore, Rikka decides to set a problem about Maximum Subsegment Sum. Given an array x of length m, its maximum subsegment sum
)
is defined as:
%20%3D%20%5Cmax_%7B1%5Cleq%20i%20%5Cleq%20j%20%5Cleq%20m%7D%20%5Cleft(%5Csum_%7Bk%3Di%7D%5Ej%20x_k%20%5Cright)%20.)
Now, given an integer array A of length n, Rikka wants you to calculate the sum of the maximum subsegment sums of all subsegments of A, i.e.
%20.)
输入描述:
The first line contains a single integer
.
The second line contains n integers
.
输出描述:
Output a single line with a single integer, the answer. The answer can be very large, therefore, you are only required to output the answer modulo
.
More formally, suppose the answer is x, you are required to find the smallest non-negative integer y satisfying
for some integer k.
示例3
输入
复制
10
1 -3 -5 7 -9 10 8 -6 -4 2