AT_arc220_b.Incomplete Shuffle
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N and integer sequences of length N: A=(A1,A2,…,AN) and B=(B1,B2,…,BN).
You perform N−1 operations on A. The i-th operation (1≤i≤N−1) is as follows:
- Choose an integer j satisfying i<j≤N, and swap the values of Ai and Aj.
Find the maximum possible number of indices k (1≤k≤N) satisfying Ak=Bk after N−1 operations.
You are given T test cases; solve each of them.
给定一个正整数 N 和两个长度为 N 的整数序列:A=(A1,A2,…,AN) 和 B=(B1,B2,…,BN)。
你将对序列 A 执行 N−1 次操作。第 i 次操作(1≤i≤N−1)如下:
- 选择一个满足 i<j≤N 的整数 j,并交换 Ai 与 Aj 的值。
求经过 N−1 次操作后,满足 Ak=Bk 的下标 k(1≤k≤N)的最大可能个数。
你将收到 T 组测试数据;请分别求解每组数据。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
A1 A2 … AN
B1 B2 … BN
输入从标准输入给出,格式如下:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N
A1 A2 … AN
B1 B2 … BN
输出格式
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 k satisfying Ak=Bk after N−1 operations can be made 2.
- When i=1: choose j=2. A=(1,1,2).
- When i=2: choose j=3. A=(1,2,1).
The number of indices k satisfying Ak=Bk after N−1 operations cannot be made greater than 2, so output 2 on the first line.
Constraints
- 1≤T≤105
- 2≤N≤3×105
- 1≤Ai,Bi≤N
- The sum of N over all test cases is at most 3×105.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过如下操作,可在 N−1 次操作后使满足 Ak=Bk 的下标 k 的个数达到 2:
- 当 i=1 时:选择 j=2,得到 A=(1,1,2)。
- 当 i=2 时:选择 j=3,得到 A=(1,2,1)。
在 N−1 次操作后,满足 Ak=Bk 的下标 k 的个数无法超过 2,因此第一行输出 2。
约束条件
- 1≤T≤105
- 2≤N≤3×105
- 1≤Ai,Bi≤N
- 所有测试用例的 N 之和不超过 3×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?