AT_abc468_c.Between P and Q

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer NN and integer sequences P=(P1,P2,…,PN)P=(P_1,P_2,\ldots, P_N) and Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\ldots,Q_N), each of which is a permutation of (1,2,…,N)(1,2,\ldots,N).

Find the number of integer sequences that are a permutation of (1,2,…,N)(1,2,\ldots,N) and are lexicographically greater than PP and lexicographically less than QQ.

What is lexicographic order for integer sequences?

For integer sequences S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) and T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}), we say that SS is lexicographically smaller than TT if 1.1. or 2.2. below holds. Here, ∣S∣,∣T∣|S|, |T| denote the lengths of S,TS, T, respectively.

  1. ∣S∣<∣T∣|S| \lt |T| and (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}).
  2. There exists an integer 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace such that both of the following two conditions hold.
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
    • SiS_i is (numerically) smaller than TiT_i.

给定一个整数 NN 以及两个整数序列 P=(P1,P2,…,PN)P=(P_1,P_2,\ldots, P_N) 和 Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\ldots,Q_N),它们均为 (1,2,…,N)(1,2,\ldots,N) 的排列。

求满足以下条件的整数序列的个数:该序列是 (1,2,…,N)(1,2,\ldots,N) 的一个排列,且字典序严格大于 PP、严格小于 QQ。

什么是整数序列的字典序?

对于整数序列 S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) 和 T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}),若满足以下条件之一,则称 SS 字典序小于 TT。其中 ∣S∣|S|、∣T∣|T| 分别表示序列 SS、TT 的长度。

  1. ∣S∣<∣T∣|S| \lt |T| 且 (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})。
  2. 存在整数 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace,使得同时满足以下两个条件:
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
    • SiS_i(数值上)小于 TiT_i。

输入格式

The input is given from Standard Input in the following format:

NN
P1P_1 P2P_2 …\ldots PNP_N
Q1Q_1 Q2Q_2 …\ldots QNQ_N

输入从标准输入中按以下格式给出:

NN
P1P_1 P2P_2 …\ldots PNP_N
Q1Q_1 Q2Q_2 …\ldots QNQ_N

输出格式

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)(2,1,3),(2,3,1) satisfy the condition. Thus, output 22.

Sample 2 Explanation:
There is no permutation of (1,2,3,4,5)(1,2,3,4,5) satisfying the condition.

Constraints

  • 1≤N≤101\le N\le 10
  • PP and QQ are integer sequences that are permutations of (1,2,…,N)(1,2,\ldots,N).
  • All input values are integers.

样例 1 解释:
有两个序列 (2,1,3)(2,1,3) 和 (2,3,1)(2,3,1) 满足条件。因此输出 22。

样例 2 解释:
不存在 (1,2,3,4,5)(1,2,3,4,5) 的满足条件的排列。

约束条件

  • 1≤N≤101\le N\le 10
  • PP 和 QQ 是 (1,2,…,N)(1,2,\ldots,N) 的排列(即整数序列)。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页