AtCoder Beginner Contest 234
G
Divide a Sequence
AtCoder
⌀ 2306
原题
← Ex→
翻译中…

Problem Statement

翻译中…

Given is a sequence $A$ of $N$ numbers.

翻译中…

There are $2^{N-1}$ ways to divide $A$ into non-empty contiguous subsequences $B_1,B_2,\ldots,B_k$. Find the value below for each of those ways, and print the sum, modulo $998244353$, of those values.

翻译中…
  • $\prod_{i=1}^{k} (\max(B_i)-\min(B_i))$
翻译中…

Here, for a sequence $B_i=(B_{i,1},B_{i,2},\ldots,B_{i,j})$, $\max(B_i)$ and $\min(B_i)$ are defined to be the maximum and minimum values of an element of $B_i$, respectively.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 3 \times 10^5$
  • $1 \leq A_i \leq 10^9$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Print the sum, modulo $998244353$, of the values found.

翻译中…

样例

Input #1
3
1 2 3
Output #1
2
There are $4$ ways to divide $A=(1,2,3)$ into non-empty contiguous subsequences, as follows. - $(1)$, $(2)$, $(3)$ - $(1)$, $(2,3)$ - $(1,2)$, $(3)$ - $(1,2,3)$ $\prod_{i=1}^{k} (\max(B_i)-\min(B_i))$ for these divisions are $0$, $0$, $0$, $2$, respectively. The sum of them, $2$, should be printed.
Input #2
4
1 10 1 10
Output #2
90
Input #3
10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
Output #3
877646588
Be sure to print the sum modulo $998244353$.
题目信息
题号
abc234_g
时间限制
2 s
内存限制
1024 MB

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