AT_arc220_b.Incomplete Shuffle

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN and integer sequences of length NN: 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).

You perform N−1N-1 operations on AA. The ii-th operation (1≤i≤N−1)(1\le i\le N-1) is as follows:

  • Choose an integer jj satisfying i<j≤Ni < j \le N, and swap the values of AiA_i and AjA_j.

Find the maximum possible number of indices kk (1≤k≤N)(1\le k\le N) satisfying Ak=BkA_k=B_k after N−1N-1 operations.

You are given TT test cases; solve each of them.

给定一个正整数 NN 和两个长度为 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 执行 N−1N-1 次操作。第 ii 次操作(1≤i≤N−11\le i\le N-1)如下:

  • 选择一个满足 i<j≤Ni < j \le N 的整数 jj,并交换 AiA_i 与 AjA_j 的值。

求经过 N−1N-1 次操作后,满足 Ak=BkA_k = B_k 的下标 kk(1≤k≤N1\le k\le N)的最大可能个数。

你将收到 TT 组测试数据;请分别求解每组数据。

输入格式

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

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N

输入从标准输入给出,格式如下:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例的格式如下:

NN
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    3
    3
    1 1 2
    1 2 3
    5
    1 2 3 4 5
    5 4 3 2 1
    6
    1 2 1 1 2 1
    1 1 1 2 2 2

    输出#1

    2
    2
    5

说明/提示

Sample 1 Explanation:
Consider the first test case.

By performing the operations as follows, the number of indices kk satisfying Ak=BkA_k=B_k after N−1N-1 operations can be made 22.

  • When i=1i=1: choose j=2j=2. A=(1,1,2)A=(1,1,2).
  • When i=2i=2: choose j=3j=3. A=(1,2,1)A=(1,2,1).

The number of indices kk satisfying Ak=BkA_k=B_k after N−1N-1 operations cannot be made greater than 22, so output 22 on the first line.

Constraints

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤3×1052\le N\le 3\times 10^5
  • 1≤Ai,Bi≤N1\le A_i,B_i\le N
  • The sum of NN over all test cases is at most 3×1053\times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

通过如下操作,可在 N−1N-1 次操作后使满足 Ak=BkA_k=B_k 的下标 kk 的个数达到 22:

  • 当 i=1i=1 时:选择 j=2j=2,得到 A=(1,1,2)A=(1,1,2)。
  • 当 i=2i=2 时:选择 j=3j=3,得到 A=(1,2,1)A=(1,2,1)。

在 N−1N-1 次操作后,满足 Ak=BkA_k=B_k 的下标 kk 的个数无法超过 22,因此第一行输出 22。

约束条件

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤3×1052\le N\le 3\times 10^5
  • 1≤Ai,Bi≤N1\le A_i,B_i\le N
  • 所有测试用例的 NN 之和不超过 3×1053\times 10^5。
  • 所有输入值均为整数。

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

首页