#abc234g. G - Divide a Sequence

G - Divide a Sequence

Score : 600600 points

问题描述

给定一个包含 NN 个数的序列 AA

2N12^{N-1} 种方式将 AA 划分成非空的 连续 子序列 B1,B2,,BkB_1,B_2,\ldots,B_k。对于每一种划分方式,计算以下值,并将这些值按照模 998244353998244353 的规则求和后输出结果。

  • i=1k(max(Bi)min(Bi))\prod_{i=1}^{k} (\max(B_i)-\min(B_i))

这里,对于子序列 Bi=(Bi,1,Bi,2,,Bi,j)B_i=(B_{i,1},B_{i,2},\ldots,B_{i,j})max(Bi)\max(B_i)min(Bi)\min(B_i) 分别定义为 BiB_i 中元素的最大值和最小值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a sequence AA of NN numbers.

There are 2N12^{N-1} ways to divide AA into non-empty contiguous subsequences B1,B2,,BkB_1,B_2,\ldots,B_k. Find the value below for each of those ways, and print the sum, modulo 998244353998244353, of those values.

  • i=1k(max(Bi)min(Bi))\prod_{i=1}^{k} (\max(B_i)-\min(B_i))

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

Constraints

  • 1N3×1051 \leq N \leq 3 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the sum, modulo 998244353998244353, of the values found.

Sample Input 1

3
1 2 3

Sample Output 1

2

There are 44 ways to divide A=(1,2,3)A=(1,2,3) into non-empty contiguous subsequences, as follows.

  • (1)(1), (2)(2), (3)(3)
  • (1)(1), (2,3)(2,3)
  • (1,2)(1,2), (3)(3)
  • (1,2,3)(1,2,3)

i=1k(max(Bi)min(Bi))\prod_{i=1}^{k} (\max(B_i)-\min(B_i)) for these divisions are 00, 00, 00, 22, respectively. The sum of them, 22, should be printed.

Sample Input 2

4
1 10 1 10

Sample Output 2

90

Sample Input 3

10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794

Sample Output 3

877646588

Be sure to print the sum modulo 998244353998244353.

update @ 2024/3/10 10:10:50