201154: [AtCoder]ARC115 E - LEQ and NEQ

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $700$ points

Problem Statement

Given is a sequence of $N$ integers $A_1,A_2,\ldots,A_N$. Print the number, modulo $998244353$, of sequences of $N$ integers $X_1,X_2,\ldots,X_N$ satisfying all of the following conditions:

  • $1 \leq X_i \leq A_i$
  • $X_i \neq X_{i+1} (1 \leq i \leq N-1)$

Constraints

  • $2 \leq N \leq 5 \times 10^5$
  • $1 \leq A_i \leq 10^9$

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print the answer.


Sample Input 1

3
2 3 2

Sample Output 1

6

The following six sequences satisfy all of the conditions.

  • $1,2,1$
  • $1,3,1$
  • $1,3,2$
  • $2,1,2$
  • $2,3,1$
  • $2,3,2$

Sample Input 2

10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 2

524691026

Input

题意翻译

给定一个长度为 $n$ 的序列 $a_1,a_2,\cdots ,a_n$,输出满足如下条件的序列 $x$ 的方案数: 1. $1\leq x_i\leq a_i$ 2. $x_i\neq x_{i+1}(1\leq i\leq n-1)$ - $2\le n\le 5\times 10^5,1\le a_i\le 10^9$

加入题单

算法标签: