AT_abc484_c.Move One Card
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given sequences A=(A1,A2,…,AN) and B=(B1,B2,…,BN) of length N consisting of positive integers.
The following operation is performed on the sequence A exactly once.
- Choose one element of A, take it out, and insert it at any position in the remaining sequence. More formally, perform the following two steps in order.
- Choose an integer i satisfying 1≤i≤N, let the sequence X=(X1,X2,…,XN−1) of length N−1 be (A1,A2,…,Ai−1,Ai+1,Ai+2,…,AN), and let the integer Y be Ai.
- Choose an integer j satisfying 1≤j≤N, and let the sequence (X1,X2,…,Xj−1,Y,Xj,Xj+1,…,XN−1) of length N be the new A.
Note that the element may be inserted at the left end or the right end of the sequence.
Determine whether it is possible to make A equal to B after the operation.
给你两个长度为 N 的正整数序列 A=(A1,A2,…,AN) 和 B=(B1,B2,…,BN)。
对序列 A 恰好执行一次如下操作:
- 从 A 中选择一个元素,将其移除,并插入到剩余序列的任意位置。更准确地说,按顺序执行以下两步:
- 选择一个满足 1≤i≤N 的整数 i,令长度为 N−1 的序列 X=(X1,X2,…,XN−1) 为 (A1,A2,…,Ai−1,Ai+1,Ai+2,…,AN),并令整数 Y 为 Ai。
- 选择一个满足 1≤j≤N 的整数 j,并将长度为 N 的序列 (X1,X2,…,Xj−1,Y,Xj,Xj+1,…,XN−1) 作为新的 A。
注意:该元素可以被插入到序列的最左端或最右端。
判断是否可以通过该操作使 A 变为 B。
输入格式
The input is given from Standard Input in the following format:
N
A1 A2 … AN
B1 B2 … BN
输入从标准输入中按以下格式给出:
N
A1 A2 … AN
B1 B2 … BN
输出格式
Print Yes in one line if it is possible to make A equal to B by performing the operation exactly once, and No otherwise.
如果恰好执行一次该操作可以使 A 等于 B,则在一行中输出 Yes;否则输出 No。
输入输出样例
输入#1
6 1 4 1 4 2 1 1 4 1 1 4 2
输出#1
Yes
输入#2
2 1 1 1 2
输出#2
No
输入#3
3 1 2 3 1 2 3
输出#3
Yes
输入#4
30 25 11 21 15 30 20 17 19 17 21 10 13 22 10 22 14 30 25 17 25 11 19 27 27 15 18 16 16 20 16 25 11 15 30 20 17 19 17 21 10 13 22 10 22 14 30 25 17 25 11 19 27 27 15 21 18 16 16 20 16
输出#4
Yes
说明/提示
Sample 1 Explanation:
For example, by taking out A6 and inserting it between the 3-rd and 4-th elements of the remaining sequence, A after the operation becomes (1,4,1,1,4,2).
Thus, print Yes.
Sample 2 Explanation:
No matter what operation is performed on A, it cannot be made equal to B.
Sample 3 Explanation:
The element taken out may be inserted back at its original position.
Constraints
- 1≤N≤2×105
- 1≤Ai≤N (1≤i≤N)
- 1≤Bi≤N (1≤i≤N)
- All input values are integers.
样例 1 解释:
例如,取出 A6,并将其插入剩余序列的第 3 个与第 4 个元素之间,则操作后的 A 变为 (1,4,1,1,4,2)。
因此,输出 Yes。
样例 2 解释:
无论对 A 执行何种操作,都无法使其等于 B。
样例 3 解释:
被取出的元素可以重新插入其原始位置。
约束条件
- 1≤N≤2×105
- 1≤Ai≤N (1≤i≤N)
- 1≤Bi≤N (1≤i≤N)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?