CF1366E.Two Arrays

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two arrays a1,a2,…,ana_1, a_2, \dots , a_n and b1,b2,…,bmb_1, b_2, \dots , b_m. Array bb is sorted in ascending order (bi<bi+1b_i \lt b_{i + 1} for each ii from 11 to m−1m - 1).

You have to divide the array aa into mm consecutive subarrays so that, for each ii from 11 to mm, the minimum on the ii-th subarray is equal to bib_i. Note that each element belongs to exactly one subarray, and they are formed in such a way: the first several elements of aa compose the first subarray, the next several elements of aa compose the second subarray, and so on.

For example, if a=[12,10,20,20,25,30]a = [12, 10, 20, 20, 25, 30] and b=[10,20,30]b = [10, 20, 30] then there are two good partitions of array aa:

  1. [12,10,20],[20,25],[30][12, 10, 20], [20, 25], [30];
  2. [12,10],[20,20,25],[30][12, 10], [20, 20, 25], [30].

You have to calculate the number of ways to divide the array aa. Since the number can be pretty large print it modulo 998244353.

给你两个数组 a1,a2,…,ana_1, a_2, \dots , a_n 和 b1,b2,…,bmb_1, b_2, \dots , b_m。数组 bb 按升序排列(即对每个从 11 到 m−1m - 1 的 ii,均有 bi<bi+1b_i \lt b_{i + 1})。

你需要将数组 aa 划分为 mm 个连续的子数组,使得对每个从 11 到 mm 的 ii,第 ii 个子数组的最小值恰好等于 bib_i。注意:每个元素恰好属于一个子数组,且这些子数组按顺序划分——aa 的前若干元素构成第一个子数组,接下来的若干元素构成第二个子数组,依此类推。

例如,若 a=[12,10,20,20,25,30]a = [12, 10, 20, 20, 25, 30] 且 b=[10,20,30]b = [10, 20, 30],则数组 aa 有如下两种合法划分:

  1. [12,10,20],[20,25],[30][12, 10, 20], [20, 25], [30];
  2. [12,10],[20,20,25],[30][12, 10], [20, 20, 25], [30]。

你需要计算划分数组 aa 的方案数。由于结果可能很大,请输出其对 998244353998244353 取模的值。

输入格式

The first line contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the length of arrays aa and bb respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots , a_n (1≤ai≤1091 \le a_i \le 10^9) — the array aa.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots , b_m (1≤bi≤109;bi<bi+11 \le b_i \le 10^9; b_i \lt b_{i+1}) — the array bb.

第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示数组 aa 和 bb 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots , a_n(1≤ai≤1091 \le a_i \le 10^9),即数组 aa。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots , b_m(1≤bi≤1091 \le b_i \le 10^9;且 bi<bi+1b_i \lt b_{i+1}),即数组 bb。

输出格式

In only line print one integer — the number of ways to divide the array aa modulo 998244353.

仅在一行中输出一个整数——将数组 aa 划分的方法数对 998244353 取模的结果。

输入输出样例

  • 输入#1

    6 3
    12 10 20 20 25 30
    10 20 30

    输出#1

    2
  • 输入#2

    4 2
    1 3 3 7
    3 7

    输出#2

    0
  • 输入#3

    8 2
    1 2 2 2 2 2 2 2
    1 2

    输出#3

    7

输入解题思路,AI测评打分。不知道怎么写?

首页