AT_abc484_c.Move One Card

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given sequences A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B1,B2,…,BN)B=(B _ 1,B _ 2,\ldots,B _ N) of length NN consisting of positive integers.

The following operation is performed on the sequence AA exactly once.

  • Choose one element of AA, 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 ii satisfying 1≤i≤N1\le i\le N, let the sequence X=(X1,X2,…,XN−1)X=(X _ 1,X _ 2,\ldots,X _ {N-1}) of length N−1N-1 be (A1,A2,…,Ai−1,Ai+1,Ai+2,…,AN)(A _ 1,A _ 2,\ldots,A _ {i-1},A _ {i+1},A _ {i+2},\ldots,A _ N), and let the integer YY be AiA _ i.
    • Choose an integer jj satisfying 1≤j≤N1\le j\le N, and let the sequence (X1,X2,…,Xj−1,Y,Xj,Xj+1,…,XN−1)(X _ 1,X _ 2,\ldots,X _ {j-1},Y,X _ j,X _ {j+1},\ldots,X _ {N-1}) of length NN be the new AA.

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 AA equal to BB after the operation.

给你两个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N) 和 B=(B1,B2,…,BN)B=(B _ 1,B _ 2,\ldots,B _ N)。

对序列 AA 恰好执行一次如下操作:

  • 从 AA 中选择一个元素,将其移除,并插入到剩余序列的任意位置。更准确地说,按顺序执行以下两步:
    • 选择一个满足 1≤i≤N1\le i\le N 的整数 ii,令长度为 N−1N-1 的序列 X=(X1,X2,…,XN−1)X=(X _ 1,X _ 2,\ldots,X _ {N-1}) 为 (A1,A2,…,Ai−1,Ai+1,Ai+2,…,AN)(A _ 1,A _ 2,\ldots,A _ {i-1},A _ {i+1},A _ {i+2},\ldots,A _ N),并令整数 YY 为 AiA _ i。
    • 选择一个满足 1≤j≤N1\le j\le N 的整数 jj,并将长度为 NN 的序列 (X1,X2,…,Xj−1,Y,Xj,Xj+1,…,XN−1)(X _ 1,X _ 2,\ldots,X _ {j-1},Y,X _ j,X _ {j+1},\ldots,X _ {N-1}) 作为新的 AA。

注意:该元素可以被插入到序列的最左端或最右端。

判断是否可以通过该操作使 AA 变为 BB。

输入格式

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

NN
A1A _ 1 A2A _ 2 …\ldots ANA _ N
B1B _ 1 B2B _ 2 …\ldots BNB _ N

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

NN
A1A _ 1 A2A _ 2 …\ldots ANA _ N
B1B _ 1 B2B _ 2 …\ldots BNB _ N

输出格式

Print Yes in one line if it is possible to make AA equal to BB by performing the operation exactly once, and No otherwise.

如果恰好执行一次该操作可以使 AA 等于 BB,则在一行中输出 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 A6A _ 6 and inserting it between the 33-rd and 44-th elements of the remaining sequence, AA after the operation becomes (1,4,1,1,4,2)(1,4,1,1,4,2).

Thus, print Yes.

Sample 2 Explanation:
No matter what operation is performed on AA, it cannot be made equal to BB.

Sample 3 Explanation:
The element taken out may be inserted back at its original position.

Constraints

  • 1≤N≤2×1051\le N\le2\times10 ^ 5
  • 1≤Ai≤N (1≤i≤N)1\le A _ i\le N\ (1\le i\le N)
  • 1≤Bi≤N (1≤i≤N)1\le B _ i\le N\ (1\le i\le N)
  • All input values are integers.

样例 1 解释:
例如,取出 A6A_6,并将其插入剩余序列的第 33 个与第 44 个元素之间,则操作后的 AA 变为 (1,4,1,1,4,2)(1,4,1,1,4,2)。

因此,输出 Yes。

样例 2 解释:
无论对 AA 执行何种操作,都无法使其等于 BB。

样例 3 解释:
被取出的元素可以重新插入其原始位置。

约束条件

  • 1≤N≤2×1051\le N\le2\times10 ^ 5
  • 1≤Ai≤N (1≤i≤N)1\le A _ i\le N\ (1\le i\le N)
  • 1≤Bi≤N (1≤i≤N)1\le B _ i\le N\ (1\le i\le N)
  • 所有输入值均为整数。

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

首页