第六回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 201)
E
Total Area of Bounding Boxes
AtCoder
⌀ 2635
原题
← DF →
翻译中…

Problem Statement

翻译中…

There are $N$ points numbered $1,2, \dots, N$ on the $2$-dimensional plane. The coordinates of point $i$ are $(i,Y_i)$. In this problem, it is guaranteed that $Y=(Y_1,Y_2,\dots ,Y_N)$ is a permutation of $(1,2, \dots ,N)$.

翻译中…

Find the sum of the areas of bounding boxes for all subsets $S$ of $\lbrace \texttt{point}\,1,\texttt{point}\,2,\dots ,\texttt{point}\,N \rbrace$ with at least $2$ elements, modulo $998244353$.

翻译中…

The bounding box for $S$ refers to the minimum area rectangle with sides parallel to the $x$-axis that contains all points in $S$ inside or on the boundary.

翻译中…

Constraints

翻译中…
  • $2 \le N \le 2 \times 10^5$
  • $Y$ is a permutation of $(1,2, \dots ,N)$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
Y_1 Y_2 \ldots Y_N

翻译中…

Output

翻译中…

Output the sum, modulo $998244353$, of the areas of bounding boxes.

翻译中…

样例

Input #1
4
2 3 1 4
Output #1
50
Each subset and the area of its bounding box are shown in the figure below. Output the sum of areas, which is $50$. ![image](https://img.atcoder.jp/arc201/d0a42940efeb582795eb4766786ddd68.png)
Input #2
26
6 14 8 19 13 25 26 22 7 3 16 15 11 24 1 12 20 23 5 17 9 2 21 10 4 18
Output #2
575187918
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。