CF1891B.Deja Vu
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of length n, consisting of positive integers, and an array x of length q, also consisting of positive integers.
There are q modification. On the i-th modification (1≤i≤q), for each j (1≤j≤n), such that aj is divisible by 2xi, you add 2xi−1 to aj. Note that xi (1≤xi≤30) is a positive integer not exceeding 30.
After all modification queries, you need to output the final array.
给你一个长度为 n 的数组 a,其中元素均为正整数;以及一个长度为 q 的数组 x,其中元素也均为正整数。
共进行 q 次修改操作。在第 i 次修改(1≤i≤q)中,对每个满足 aj 能被 2xi 整除的下标 j(1≤j≤n),将 2xi−1 加到 aj 上。注意:xi(1≤xi≤30)是不超过 30 的正整数。
完成所有修改操作后,你需要输出最终的数组。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n,q≤105) —the length of the array a and the number of queries respectively.
The second line of each test case contains n integers a1,a2,a3,…,an — the elements of the array a (1≤ai≤109).
The third line of each test case contains q integers x1,x2,x3,…,xq — the elements of the array x (1≤xi≤30), which are the modification queries.
It is guaranteed that the sum of n and the sum of q across all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤105)——数组 a 的长度和查询次数。
每个测试用例的第二行包含 n 个整数 a1,a2,a3,…,an —— 数组 a 的元素(1≤ai≤109)。
每个测试用例的第三行包含 q 个整数 x1,x2,x3,…,xq —— 数组 x 的元素(1≤xi≤30),表示修改操作的参数。
保证所有测试用例中 n 的总和与 q 的总和均不超过 2⋅105。
输出格式
For each test case, output the array after all of the modification queries.
对于每个测试用例,输出执行完所有修改查询后的数组。
输入输出样例
输入#1
4 5 3 1 2 3 4 4 2 3 4 7 3 7 8 12 36 48 6 3 10 4 2 5 4 2 2 2 2 2 1 1 1 1 5 5 1 2 4 8 16 5 2 3 4 1
输出#1
1 2 3 6 6 7 10 14 38 58 6 3 3 3 3 3 3 1 3 7 11 19
说明/提示
In the first test case, the first query will add 2 to the integers in positions 4 and 5. After this addition, the array would be [1,2,3,6,6]. Other operations will not modify the array.
In the second test case, the first modification query does not change the array. The second modification query will add 8 to the integer in position 5, so that the array would look like this: [7,8,12,36,56,6,3]. The third modification query will add 2 to the integers in positions 2,3, 4 and 5. The array would then look like this: [7,10,14,38,58,6,3].
在第一个测试用例中,第一个查询会将位置 4 和 5 上的整数各加 2。执行该加法操作后,数组变为 [1,2,3,6,6]。其余操作不会修改该数组。
在第二个测试用例中,第一个修改查询不会改变数组。第二个修改查询会将位置 5 上的整数加 8,使得数组变为:[7,8,12,36,56,6,3]。第三个修改查询会将位置 2、3、4 和 5 上的整数各加 2,此时数组变为:[7,10,14,38,58,6,3]。
输入解题思路,AI测评打分。不知道怎么写?