Public Judge

pjudge

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#21750. 【PR #8】消愁

Statistics

对于两个排列 $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}$

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.