#P10162. [DTCPC 2024] 序列

    ID: 11526 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树2024分治洛谷月赛均摊分析

[DTCPC 2024] 序列

Problem Description

Define the weight f({pn})f(\{p_n\}) of a sequence {pn}\{p_n\} of length nn as maxi=1n{pimax{pi1,pi+1}}\max\limits_{i=1}^n\{p_i-\max\{p_{i-1},p_{i+1}\}\}. In particular, define p0=pn+1=infp_0=p_{n+1}=-\inf.

Compute $\sum\limits_{l=1}^n \sum\limits_{r=l+1}^n f(\{a_l,a_{l+1},\dots,a_r\})$.

The answer is taken modulo 2322^{32}.

Input Format

The first line contains a positive integer nn (1n1061 \le n \le 10^6).

The second line contains nn integers aia_i (1ai1091 \le a_i \le 10^9).

Output Format

Output one number representing the answer.

The answer is taken modulo 2322^{32}.

5
1 3 5 2 3

21
4
4 6 3 3
12

Hint

Translated by ChatGPT 5