当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7173:Two Permutations

题目描述
There are two permutations $P_1,P_2,\dots,P_n$, $Q_1,Q_2,\dots,Q_n$ and a sequence $R$. Initially, $R$ is empty. While at least one of $P$ and $Q$ is non-empty, you need to choose a non-empty array ($P$ or $Q$), pop its leftmost element, and attach it to the right end of $R$. Finally, you will get a sequence $R$ of length $2n$.

You will be given a sequence $S$ of length $2n$, please count the number of possible ways to merge $P$ and $Q$ into $R$ such that $R=S$. Two ways are considered different if and only if you choose the element from different arrays in a step.
输入解释
The first line contains a single integer $T$ ($1 \leq T \leq 300$), the number of test cases. For each test case:

The first line contains a single integer $n$ ($1 \leq n \leq 300\,000$), denoting the length of each permutation.

The second line contains $n$ distinct integers $P_1,P_2,\dots,P_n$ ($1\leq P_i\leq n$).

The third line contains $n$ distinct integers $Q_1,Q_2,\dots,Q_n$ ($1\leq Q_i\leq n$).

The fourth line contains $2n$ integers $S_1,S_2,\dots,S_{2n}$ ($1\leq S_i\leq n$).

It is guaranteed that the sum of all $n$ is at most $2\,000\,000$.
输出解释
For each test case, output a single line containing an integer, denoting the number of possible ways. Note that the answer may be extremely large, so please print it modulo $998\,244\,353$ instead.
输入样例
2
3
1 2 3
1 2 3
1 2 1 3 2 3
2
1 2
1 2
1 2 2 1
输出样例
2
0

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7173

最后修改于 2022-09-15T06:17:10+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/4000MS(Java/Others) 524288/524288K(Java/Others)