#abc222d. D - Between Two Arrays

D - Between Two Arrays

Score : 400400 points

问题描述

若一个包含 nn 个数的序列 S=(s1,s2,,sn)S = (s_1, s_2, \dots, s_n) 满足对于所有 ii (1in1)(1 \leq i \leq n - 1) 都有 sisi+1s_i \leq s_{i+1},则称该序列为 非递减 序列。

已知两个均为非递减序列的整数序列:A=(a1,a2,,aN)A = (a_1, a_2, \dots, a_N)B=(b1,b2,,bN)B = (b_1, b_2, \dots, b_N)
考虑一个满足以下条件的包含 NN 个整数的非递减序列 C=(c1,c2,,cN)C = (c_1, c_2, \dots, c_N)

  • 对于所有 ii (1iN)(1 \leq i \leq N),都有 aicibia_i \leq c_i \leq b_i

求出可能成为序列 CC 的序列数量,结果对 998244353998244353 取模。

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

Problem Statement

A sequence of nn numbers, S=(s1,s2,,sn)S = (s_1, s_2, \dots, s_n), is said to be non-decreasing if and only if sisi+1s_i \leq s_{i+1} holds for every ii (1in1)(1 \leq i \leq n - 1).

Given are non-decreasing sequences of NN integers each: A=(a1,a2,,aN)A = (a_1, a_2, \dots, a_N) and B=(b1,b2,,bN)B = (b_1, b_2, \dots, b_N).
Consider a non-decreasing sequence of NN integers, C=(c1,c2,,cN)C = (c_1, c_2, \dots, c_N), that satisfies the following condition:

  • aicibia_i \leq c_i \leq b_i for every ii (1iN)(1 \leq i \leq N).

Find the number, modulo 998244353998244353, of sequences that can be CC.

Constraints

  • 1N30001 \leq N \leq 3000
  • 0aibi30000 \leq a_i \leq b_i \leq 3000 (1iN)(1 \leq i \leq N)
  • The sequences AA and BB are non-decreasing.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 \dots aNa_N

b1b_1 b2b_2 \dots bNb_N

Output

Print the number, modulo 998244353998244353, of sequences that can be CC.

Sample Input 1

2
1 1
2 3

Sample Output 1

5

There are five sequences that can be CC, as follows.

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

Note that (2,1)(2, 1) does not satisfy the condition since it is not non-decreasing.

Sample Input 2

3
2 2 2
2 2 2

Sample Output 2

1

There is one sequence that can be CC, as follows.

  • (2,2,2)(2, 2, 2)

Sample Input 3

10
1 2 3 4 5 6 7 8 9 10
1 4 9 16 25 36 49 64 81 100

Sample Output 3

978222082

Be sure to find the count modulo 998244353998244353.

update @ 2024/3/10 09:47:11