B. Deja Vu

time limit per test

2 seconds

memory limit per test

256 megabytes

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.

Input

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.

Output

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

Example

Input

Copy

复制代码

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

Copy

复制代码
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.

4

4

解题说明:此题是一道模拟题,给定一个数组 arr 和一组指数 t,按照从小到大的顺序,对数组中能被 2^t 整除的元素,加上 2^(t-1)。每个指数最多使用一次,且一旦使用到最小值就停止。对每个指数 t[j],检查数组元素 arr[k] 是否能被 2^t[j] 整除,如果能整除,则加上 2^(t[j]-1)。

cpp 复制代码
#include<stdio.h>
#include<math.h>
int main() 
{
    int test = 0;
    scanf("%d", &test);
    for (int i = 0; i < test; i++)
    {
        int n = 0, x = 0;
        scanf("%d", &n);
        scanf("%d", &x);
        int arr[n];
        int t[x];
        for (int j = 0; j < n; j++) 
        {
            scanf("%d", &arr[j]);
        }
        int min = 0;
        int c = 0;
        for (int j = 0; j < x; j++) 
        {
            scanf("%d", &t[j]);
            if (j == 0) 
            {
                min = t[j];
            }
            if (min > t[j])
            {
                min = t[j];
                c = j;
            }
        }
        int num = t[0];
        for (int j = 0; j < c + 1; j++) 
        {
            if (num >= t[j]) 
            {
                for (int k = 0; k < n; k++) 
                {
                    if (arr[k] % (int)pow(2, t[j]) == 0) 
                    {
                        arr[k] = arr[k] + (int)pow(2, t[j] - 1);
                    }
                }
                if (min == t[j])
                {
                    break;
                }
                num = t[j];
            }
        }
        for (int j = 0; j < n; j++)
        {
            printf("%d ", arr[j]);
        }
        printf("\n");
    }
    return 0;
}
相关推荐
秋天的怀念_David7 分钟前
算法一千零一夜 · 第三十七夜 · 类型的过路费
java·程序人生·算法
xckkcxxck2 小时前
Kaggle S6E10 冠军方案精读(二):245 个模型的合唱团,和一个只会“线性指挥“的老师
算法
饮水桶_T3 小时前
Git笔记
开发语言·笔记·算法
指掀涛澜天下惊3 小时前
强化学习进阶篇十四 DPO算法
深度学习·算法·机器学习·sft·预训练·dpo
AAA修煤气灶刘哥5 小时前
我都切到下一张图了,Agent 怎么还在解释上一张?
人工智能·算法·架构
Navigator_Z5 小时前
LeetCode //C - 1320. Minimum Distance to Type a Word Using Two Fingers
c语言·算法·leetcode
青少儿编程课堂7 小时前
蓝桥杯青少组图形化真题:校园无人机编队灯光秀解析(全国青少年信息素养大赛·电子学会12月图形化考级同源考点)
c++·python·算法·bfs·信息学竞赛
Shadow(⊙o⊙)8 小时前
专题六:模拟算法
算法
民乐团扒谱机1 天前
【超详细】基频音高提取算法之SWIPE 算法深度解析:频谱匹配的精度极限与工程边界
人工智能·算法