P 与 Q 之间AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given an integer $N$ and integer sequences $P=(P_1,P_2,\ldots, P_N)$ and $Q=(Q_1,Q_2,\ldots,Q_N)$, each of which is a permutation of $(1,2,\ldots,N)$.
Find the number of integer sequences that are a permutation of $(1,2,\ldots,N)$ and are lexicographically greater than $P$ and lexicographically less than $Q$.
What is lexicographic order for integer sequences? For integer sequences $S = (S_1,S_2,\ldots,S_{|S|})$ and $T = (T_1,T_2,\ldots,T_{|T|})$, we say that $S$ is lexicographically smaller than $T$ if $1.$ or $2.$ below holds. Here, $|S|, |T|$ denote the lengths of $S, T$, respectively. $|S| \lt |T|$ and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following two conditions hold. $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$ $S_i$ is (numerically) smaller than $T_i$.
给定一个整数 $N$ 和两个整数序列 $P=(P_1,P_2,\ldots, P_N)$、$Q=(Q_1,Q_2,\ldots,Q_N)$,它们都是 $(1,2,\ldots,N)$ 的排列。
求满足以下条件的整数序列的数量:该序列是 $(1,2,\ldots,N)$ 的排列,且按字典序大于 $P$ 且按字典序小于 $Q$。
整数序列的字典序是什么?对于整数序列 $S = (S_1,S_2,\ldots,S_{|S|})$ 和 $T = (T_1,T_2,\ldots,T_{|T|})$,如果满足以下条件 1. 或 2. 中的至少一个,则称 $S$ 按字典序小于 $T$。其中,$|S|, |T|$ 分别表示 $S, T$ 的长度。
$|S| \lt |T|$,且$(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$。- 存在一个整数
$1 \leq i \leq \min\lbrace |S|, |T| \rbrace$,使得同时满足以下两个条件:$(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$,并且$S_i$在数值上小于$T_i$。
Constraints
约束条件
AI (CI翻译)$1\le N\le 10$$P$and$Q$are integer sequences that are permutations of$(1,2,\ldots,N)$.- All input values are integers.
$1\le N\le 10$$P$和$Q$是$(1,2,\ldots,N)$的排列。- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N
P_1 P_2 \ldots P_N
Q_1 Q_2 \ldots Q_N
N
P_1 P_2 \ldots P_N
Q_1 Q_2 \ldots Q_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer.
输出答案。AI (CI翻译)
样例
3
1 3 2
3 1 2
2
5
5 4 2 1 3
5 1 2 3 4
0
7
3 6 5 2 7 1 4
4 1 5 7 2 3 6
223
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。