310810: CF1891B. Deja Vu

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Deja Vutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 \leq i \leq q$), for each $j$ ($1 \leq j \leq n$), such that $a_j$ is divisible by $2^{x_i}$, you add $2^{x_i-1}$ to $a_j$. Note that $x_i$ ($1 \leq x_i \leq 30$) is a positive integer not exceeding 30.

After all modification queries, you need to output the final array.

Input

The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — 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 \leq n, q \leq 10^5$) —the length of the array $a$ and the number of queries respectively.

The second line of each test case contains $n$ integers $a_1, a_2, a_3, \ldots, a_n$ — the elements of the array $a$ ($1 \leq a_i \leq 10^9$).

The third line of each test case contains $q$ integers $x_1, x_2, x_3, \ldots, x_q$ — the elements of the array $x$ ($1 \leq x_i \leq 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 \cdot 10^5$.

Output

For each test case, output the array after all of the modification queries.

ExampleInput
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
Output
1 2 3 6 6 
7 10 14 38 58 6 3 
3 3 3 3 3 
1 3 7 11 19 
Note

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]$.

Output

题目大意:
给定一个长度为n的由正整数组成的数组a,以及一个长度为q的由正整数组成的数组x。有q次修改操作,在第i次修改操作中(1≤i≤q),对于每个j(1≤j≤n),如果a[j]能被2^{x_i}整除,则将2^{x_i-1}加到a[j]上。注意x_i(1≤x_i≤30)是一个不超过30的正整数。在所有修改操作完成后,需要输出最终的数组。

输入数据格式:
第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行包含两个整数n和q(1≤n, q≤10^5),分别表示数组a的长度和查询的数量。
每个测试用例的第二行包含n个整数a_1, a_2, a_3, …, a_n,表示数组a的元素(1≤a_i≤10^9)。
每个测试用例的第三行包含q个整数x_1, x_2, x_3, …, x_q,表示数组x的元素(1≤x_i≤30),它们是修改操作的查询。
保证所有测试用例的n和q之和不超过2×10^5。

输出数据格式:
对于每个测试用例,输出所有修改操作后的数组。

示例输入输出(Input/Output):
```
Input
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

Output
1 2 3 6 6
7 10 14 38 58 6 3
3 3 3 3 3
1 3 7 11 19
```题目大意: 给定一个长度为n的由正整数组成的数组a,以及一个长度为q的由正整数组成的数组x。有q次修改操作,在第i次修改操作中(1≤i≤q),对于每个j(1≤j≤n),如果a[j]能被2^{x_i}整除,则将2^{x_i-1}加到a[j]上。注意x_i(1≤x_i≤30)是一个不超过30的正整数。在所有修改操作完成后,需要输出最终的数组。 输入数据格式: 第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含两个整数n和q(1≤n, q≤10^5),分别表示数组a的长度和查询的数量。 每个测试用例的第二行包含n个整数a_1, a_2, a_3, …, a_n,表示数组a的元素(1≤a_i≤10^9)。 每个测试用例的第三行包含q个整数x_1, x_2, x_3, …, x_q,表示数组x的元素(1≤x_i≤30),它们是修改操作的查询。 保证所有测试用例的n和q之和不超过2×10^5。 输出数据格式: 对于每个测试用例,输出所有修改操作后的数组。 示例输入输出(Input/Output): ``` Input 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 Output 1 2 3 6 6 7 10 14 38 58 6 3 3 3 3 3 3 1 3 7 11 19 ```

加入题单

上一题 下一题 算法标签: