Public Judge

pjudge

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Hackable ✓
الإحصائيات

对于两个排列 $p,q$,称 01 串 $s$ 是消愁的当且仅当存在存在一个 $2\times n$ 的矩阵 $a$ 满足:

  1. $1$ 到 $2n$ 中的每个元素都在矩阵中出现。
  2. $a_{1,i}\lt a_{1,j}$ 当且仅当 $p_i\lt p_j$
  3. $a_{2,i}\lt a_{2,j}$ 当且仅当 $q_i\lt q_j$
  4. $a_{1,i}\lt a_{2,i}$ 当且仅当 $s_i=0$

定义 $f(p,q)$ 为有多少 01 串对于这两个排列是消愁的。

现在给定排列 $q$ 的一部分和排列 $p$,求对于所有把 $q$ 补全的方案,$f(p,q)$ 之和。

输入格式

第一行一个整数 $n$ 表示排列长度。

第二行 $n$ 个整数表示排列 $p$。

第三行 $n$ 个整数表示排列 $q$ 的一部分,如果 $q_i=0$ 表示这一位不确定。

输出格式

输出 $f(p,q)$ 的和对 $998244353$ 取模后的结果。

样例一

input

2
1 2
2 1

output

3

explanation

00 对应

1 2
4 3

11 对应

3 4
2 1

01 对应

1 4
3 2

样例二

input

4
4 3 2 1
4 3 2 1

output

16

样例三

input

5
1 2 3 4 5
0 0 0 0 0

output

1546

样例四

input

6
1 6 2 5 3 4
0 1 0 2 0 3

output

52

数据范围与提示

对于 $100\%$ 的数据,$1\leq n\leq 100,1\leq p_i\leq n,0\leq q_i\leq n$,对于 $i\neq j$,$p_i\neq p_j$,且若 $q_iq_j\neq 0$,$q_i\neq q_j$。

测试点编号 $n\leq$ 特殊性质
$1\sim 4$ $5$
$5\sim 9$ $100$ $q_i\neq 0$
$10\sim 14$ $100$ $q_i=0$
$15\sim 20$ $100$

时间限制:$2\texttt{s}$

空间限制:$512\texttt{MB}$

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.