CF1704G.Mio and Lucky Array

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mio has an array aa consisting of nn integers, and an array bb consisting of mm integers.

Mio can do the following operation to aa:

  • Choose an integer ii (1≤i≤n1 \leq i \leq n) that has not been chosen before, then add 11 to aia_i, subtract 22 from ai+1a_{i+1}, add 33 to ai+2a_{i+2} an so on. Formally, the operation is to add $(-1)^{j-i} \cdot (j-i+1) $ to aja_j for i≤j≤ni \leq j \leq n.

Mio wants to transform aa so that it will contain bb as a subarray. Could you answer her question, and provide a sequence of operations to do so, if it is possible?

An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

米奥有一个由 nn 个整数组成的数组 aa,以及一个由 mm 个整数组成的数组 bb。

米奥可以对 aa 执行如下操作:

  • 选择一个之前未被选过的整数 ii(满足 1≤i≤n1 \leq i \leq n),然后将 aia_i 加 11,将 ai+1a_{i+1} 减 22,将 ai+2a_{i+2} 加 33,依此类推。形式化地,该操作是对每个满足 i≤j≤ni \leq j \leq n 的下标 jj,将 aja_j 增加 (−1)j−i⋅(j−i+1)(-1)^{j-i} \cdot (j-i+1)。

米奥希望将 aa 变换为一个包含 bb 作为子数组的数组。你能回答她的问题吗?如果可行,请给出一组合法的操作序列。

若数组 bb 可通过从数组 aa 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 bb 是 aa 的一个子数组。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains one integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the number of elements in aa.

The second line of the test case contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (−105≤ai≤105-10^5 \leq a_i \leq 10^5), where aia_i is the ii-th element of aa.

The third line of the test case contains one integer mm (2≤m≤n2 \leq m \leq n) — the number of elements in bb.

The fourth line of the test case contains mm integers b1,b2,⋯ ,bmb_1, b_2, \cdots, b_m (−1012≤bi≤1012-10^{12} \leq b_i \leq 10^{12}), where bib_i is the ii-th element of bb.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5),表示数组 aa 的元素个数。

每个测试用例的第二行包含 nn 个整数 a1,a2,⋯ ,ana_1, a_2, \cdots, a_n(−105≤ai≤105-10^5 \leq a_i \leq 10^5),其中 aia_i 是数组 aa 的第 ii 个元素。

每个测试用例的第三行包含一个整数 mm(2≤m≤n2 \leq m \leq n),表示数组 bb 的元素个数。

每个测试用例的第四行包含 mm 个整数 b1,b2,⋯ ,bmb_1, b_2, \cdots, b_m(−1012≤bi≤1012-10^{12} \leq b_i \leq 10^{12}),其中 bib_i 是数组 bb 的第 ii 个元素。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

If it is impossible to transform aa so that it contains bb as a subarray, output −1-1.

Otherwise, the first line of output should contain an integer kk (0≤k≤n0 \leq k \leq n), the number of operations to be done.

The second line should contain kk distinct integers, representing the operations done in order.

If there are multiple solutions, you can output any.

Notice that you do not need to minimize the number of operations.

如果无法通过变换使 aa 包含 bb 作为其子数组,则输出 −1-1。

否则,输出的第一行应包含一个整数 kk(0≤k≤n0 \leq k \leq n),表示所需执行的操作次数。

第二行应包含 kk 个互不相同的整数,表示按顺序执行的操作。

若存在多种解法,输出任意一种即可。

注意:你无需最小化操作次数。

输入输出样例

  • 输入#1

    5
    5
    1 2 3 4 5
    5
    2 0 6 0 10
    5
    1 2 3 4 5
    3
    3 5 3
    8
    -3 2 -3 -4 4 0 1 -2
    4
    10 -6 7 -7
    5
    1 2 3 4 5
    4
    1 10 1 1
    5
    0 0 0 0 0
    2
    10 12

    输出#1

    1
    1 
    1
    4 
    5
    1 3 4 6 8 
    -1
    -1

说明/提示

In the first test case, the sequence aa = [1,2,3,4,5][1,2,3,4,5]. One of the possible solutions is doing one operation at i=1i = 1 (add 11 to a1a_1, subtract 22 from a2a_2, add 33 to a3a_3, subtract 44 from a4a_4, add 55 to a5a_5). Then array aa is transformed to aa = [2,0,6,0,10][2,0,6,0,10], which contains bb = [2,0,6,0,10][2, 0, 6, 0, 10] as a subarray.

In the second test case, the sequence aa = [1,2,3,4,5][1,2,3,4,5]. One of the possible solutions is doing one operation at i=4i = 4 (add 11 to a4a_4, subtract 22 from a5a_5). Then array aa is transformed to aa = [1,2,3,5,3][1,2,3,5,3], which contains bb = [3,5,3][3,5,3] as a subarray.

In the third test case, the sequence aa = [−3,2,−3,−4,4,0,1,−2][-3, 2, -3, -4, 4, 0, 1, -2]. One of the possible solutions is the following.

  • Choose an integer i=8i=8 to do the operation. Then array aa is transformed to aa = [−3,2,−3,−4,4,0,1,−1][-3, 2, -3, -4, 4, 0, 1, -1].
  • Choose an integer i=6i=6 to do the operation. Then array aa is transformed to aa = [−3,2,−3,−4,4,1,−1,2][-3, 2, -3, -4, 4, 1, -1, 2].
  • Choose an integer i=4i=4 to do the operation. Then array aa is transformed to aa = [−3,2,−3,−3,2,4,−5,7][-3, 2, -3, -3, 2, 4, -5, 7].
  • Choose an integer i=3i=3 to do the operation. Then array aa is transformed to aa = [−3,2,−2,−5,5,0,0,1][-3, 2, -2, -5, 5, 0, 0, 1].
  • Choose an integer i=1i=1 to do the operation. Then array aa is transformed to aa = [−2,0,1,−9,10,−6,7,−7][-2, 0, 1, -9, 10, -6, 7, -7].

The resulting aa is [−2,0,1,−9,10,−6,7,−7][-2, 0, 1, -9, 10, -6, 7, -7], which contains bb = [10,−6,7,−7][10, -6, 7, -7] as a subarray.

In the fourth test case, it is impossible to transform aa so that it contains bb as a subarray.

In the fifth test case, it is impossible to transform aa so that it contains bb as a subarray.

在第一个测试用例中,序列 aa = [1,2,3,4,5][1,2,3,4,5]。一种可能的解法是在 i=1i = 1 处执行一次操作(对 a1a_1 加 11,对 a2a_2 减 22,对 a3a_3 加 33,对 a4a_4 减 44,对 a5a_5 加 55)。此时数组 aa 变为 aa = [2,0,6,0,10][2,0,6,0,10],其中包含子数组 bb = [2,0,6,0,10][2, 0, 6, 0, 10]。

在第二个测试用例中,序列 aa = [1,2,3,4,5][1,2,3,4,5]。一种可能的解法是在 i=4i = 4 处执行一次操作(对 a4a_4 加 11,对 a5a_5 减 22)。此时数组 aa 变为 aa = [1,2,3,5,3][1,2,3,5,3],其中包含子数组 bb = [3,5,3][3,5,3]。

在第三个测试用例中,序列 aa = [−3,2,−3,−4,4,0,1,−2][-3, 2, -3, -4, 4, 0, 1, -2]。一种可能的解法如下:

  • 选择整数 i=8i=8 执行操作,则数组 aa 变为 aa = [−3,2,−3,−4,4,0,1,−1][-3, 2, -3, -4, 4, 0, 1, -1]。
  • 选择整数 i=6i=6 执行操作,则数组 aa 变为 aa = [−3,2,−3,−4,4,1,−1,2][-3, 2, -3, -4, 4, 1, -1, 2]。
  • 选择整数 i=4i=4 执行操作,则数组 aa 变为 aa = [−3,2,−3,−3,2,4,−5,7][-3, 2, -3, -3, 2, 4, -5, 7]。
  • 选择整数 i=3i=3 执行操作,则数组 aa 变为 aa = [−3,2,−2,−5,5,0,0,1][-3, 2, -2, -5, 5, 0, 0, 1]。
  • 选择整数 i=1i=1 执行操作,则数组 aa 变为 aa = [−2,0,1,−9,10,−6,7,−7][-2, 0, 1, -9, 10, -6, 7, -7]。

最终得到的 aa 为 [−2,0,1,−9,10,−6,7,−7][-2, 0, 1, -9, 10, -6, 7, -7],其中包含子数组 bb = [10,−6,7,−7][10, -6, 7, -7]。

在第四个测试用例中,无法将 aa 变换为包含 bb 作为子数组的数组。

在第五个测试用例中,无法将 aa 变换为包含 bb 作为子数组的数组。

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

首页