CF1366E.Two Arrays
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a1,a2,…,an and b1,b2,…,bm . Array b is sorted in ascending order ( bi<bi+1 for each i from 1 to m−1 ).
You have to divide the array a into m consecutive subarrays so that, for each i from 1 to m , the minimum on the i -th subarray is equal to bi . Note that each element belongs to exactly one subarray, and they are formed in such a way: the first several elements of a compose the first subarray, the next several elements of a compose the second subarray, and so on.
For example, if a=[12,10,20,20,25,30] and b=[10,20,30] then there are two good partitions of array a :
- [12,10,20],[20,25],[30] ;
- [12,10],[20,20,25],[30] .
You have to calculate the number of ways to divide the array a . Since the number can be pretty large print it modulo 998244353.
输入格式
The first line contains two integers n and m ( 1≤n,m≤2⋅105 ) — the length of arrays a and b respectively.
The second line contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the array a .
The third line contains m integers b1,b2,…,bm ( 1≤bi≤109;bi<bi+1 ) — the array b .
输出格式
In only line print one integer — the number of ways to divide the array a modulo 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