A16347 | Deja Vu
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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$ .
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$ .
输出格式
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]$ .
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]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted