#P6406. [COCI 2014/2015 #2] Norma

    ID: 6644 远端评测题 2000ms 64MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2014递归O2优化分治COCI(克罗地亚)

[COCI 2014/2015 #2] Norma

Problem Description

Given a positive integer sequence a1,a2,,ana_1,a_2,\cdots,a_n, compute

$$\sum_{i=1}^{n}\sum_{j=i}^{n}(j-i+1)\min(a_i,a_{i+1},\cdots,a_j)\max(a_i,a_{i+1},\cdots,a_j)$$

Input Format

The first line contains an integer nn.
The next nn lines each contain a positive integer, representing the input sequence a1,a2,,ana_1,a_2,\cdots,a_n.

Output Format

Output the result modulo 10910^9.

4
2
4
1
4
109

Hint

For 100%100\% of the testdata, 1n5×1051 \le n \leq 5\times 10^5, 1ai1081 \le a_i \le 10^8.

Translated by ChatGPT 5