AT_abc468_c.Between P and Q
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer N and integer sequences P=(P1,P2,…,PN) and Q=(Q1,Q2,…,QN), each of which is a permutation of (1,2,…,N).
Find the number of integer sequences that are a permutation of (1,2,…,N) and are lexicographically greater than P and lexicographically less than Q.
What is lexicographic order for integer sequences?
For integer sequences S=(S1,S2,…,S∣S∣) and T=(T1,T2,…,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∣<∣T∣ and (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣).
- There exists an integer 1≤i≤min{∣S∣,∣T∣} such that both of the following two conditions hold.
- (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)
- Si is (numerically) smaller than Ti.
给定一个整数 N 以及两个整数序列 P=(P1,P2,…,PN) 和 Q=(Q1,Q2,…,QN),它们均为 (1,2,…,N) 的排列。
求满足以下条件的整数序列的个数:该序列是 (1,2,…,N) 的一个排列,且字典序严格大于 P、严格小于 Q。
什么是整数序列的字典序?
对于整数序列 S=(S1,S2,…,S∣S∣) 和 T=(T1,T2,…,T∣T∣),若满足以下条件之一,则称 S 字典序小于 T。其中 ∣S∣、∣T∣ 分别表示序列 S、T 的长度。
- ∣S∣<∣T∣ 且 (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)。
- 存在整数 1≤i≤min{∣S∣,∣T∣},使得同时满足以下两个条件:
- (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)
- Si(数值上)小于 Ti。
输入格式
The input is given from Standard Input in the following format:
N
P1 P2 … PN
Q1 Q2 … QN
输入从标准输入中按以下格式给出:
N
P1 P2 … PN
Q1 Q2 … QN
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
3 1 3 2 3 1 2
输出#1
2
输入#2
5 5 4 2 1 3 5 1 2 3 4
输出#2
0
输入#3
7 3 6 5 2 7 1 4 4 1 5 7 2 3 6
输出#3
223
说明/提示
Sample 1 Explanation:
Two sequences (2,1,3),(2,3,1) satisfy the condition. Thus, output 2.
Sample 2 Explanation:
There is no permutation of (1,2,3,4,5) satisfying the condition.
Constraints
- 1≤N≤10
- P and Q are integer sequences that are permutations of (1,2,…,N).
- All input values are integers.
样例 1 解释:
有两个序列 (2,1,3) 和 (2,3,1) 满足条件。因此输出 2。
样例 2 解释:
不存在 (1,2,3,4,5) 的满足条件的排列。
约束条件
- 1≤N≤10
- P 和 Q 是 (1,2,…,N) 的排列(即整数序列)。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?