CF2161H.Cycle Sort
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integer arrays a0,…,an−1 and b0,…,bm−1. Each integer among 1,…,n+m is present exactly once among a0,…,an−1,b0,…,bm−1.
We perform k operations on the arrays. Namely, for each integer i from 0 to k−1 in this order
- if aimodn>bimodm, we swap aimodn and bimodm
- otherwise, we do nothing
Determine the final state of both arrays after all k operations are completed.
给你两个整数数组 a0,…,an−1 和 b0,…,bm−1。在 a0,…,an−1,b0,…,bm−1 中,1,…,n+m 中的每个整数恰好出现一次。
我们对这两个数组执行 k 次操作。具体来说,按顺序对每个从 0 到 k−1 的整数 i 执行以下操作:
- 若 aimodn>bimodm,则交换 aimodn 与 bimodm;
- 否则,不进行任何操作。
请确定在完成全部 k 次操作后,两个数组的最终状态。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains three integers n,m,k (1≤n,m≤2⋅105, 0≤k≤1018).
The second line contains n integers a0,…,an−1.
The third line contains m integers b0,…,bm−1.
It is guaranteed that the joint sequence a0,…,an−1,b0,…,bm−1 is a permutation of integers from 1 to n+m.
The sum of n+m over all testcases doesn't exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n,m,k(1≤n,m≤2⋅105,0≤k≤1018)。
第二行包含 n 个整数 a0,…,an−1。
第三行包含 m 个整数 b0,…,bm−1。
保证联合序列 a0,…,an−1,b0,…,bm−1 是 1 到 n+m 的一个排列。
所有测试用例中 n+m 的总和不超过 2⋅105。
输出格式
For each testcase, print two lines — the states of the arrays a0,…,an−1 and b0,…,bm−1 after the k operations are performed as described above.
对于每个测试用例,输出两行——分别表示执行上述 k 次操作后数组 a0,…,an−1 和 b0,…,bm−1 的状态。
输入输出样例
输入#1
3 2 3 5 3 4 1 5 2 1 5 4 6 5 4 3 2 1 3 3 0 4 5 6 1 2 3
输出#1
1 3 4 5 2 2 6 5 4 3 1 4 5 6 1 2 3
说明/提示
The action sequence for the first example
i
imodn
imodm
comparison
action
array a
array b
0
0
0
3>1
swap a0 and b0
[1, 4]
[3, 5, 2]
1
1
1
4<5
nothing
[1, 4]
[3, 5, 2]
2
0
2
1<2
nothing
[1, 4]
[3, 5, 2]
3
1
0
4>3
swap a1 and b0
[1, 3]
[4, 5, 2]
4
0
1
1<5
nothing
[1, 3]
[4, 5, 2]
第一个示例的动作序列
i
imodn
imodm
比较
动作
数组 a
数组 b
0
0
0
3>1
交换 a0 和 b0
[1, 4]
[3, 5, 2]
1
1
1
4<5
无操作
[1, 4]
[3, 5, 2]
2
0
2
1<2
无操作
[1, 4]
[3, 5, 2]
3
1
0
4>3
交换 a1 和 b0
[1, 3]
[4, 5, 2]
4
0
1
1<5
无操作
[1, 3]
[4, 5, 2]
输入解题思路,AI测评打分。不知道怎么写?