欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2234D.XOR, Expression and Two Binary Numbers
XOR, Expression and Two Binary Numbers
You are given an integer . There is a sequence of -bit binary numbers . The numbers and are given to you, and the others are unknown. Then the unknown numbers are filled in as follows over steps:
- Suppose that before the -th step, the numbers with indices have already been filled. (Before the first step, these are the numbers with indices ).
- Then for each from to , the assignment $a_{\frac{p_j + p_{j + 1}}{2}} := a_{p_j} \oplus a_{p_{j + 1}}$ is performed.
- These assignments happen simultaneously, and after that all these numbers also become filled.
It can be shown that this process always fills all numbers completely.
This is what the process looks like for and , where initially :
- Before the first step, the numbers with indices are filled. Therefore, this operation will perform $a_3 := a_1 \oplus a_5 = \texttt{010} \oplus \texttt{110} = \texttt{100}$.
- Before the second step, the numbers with indices are filled. Therefore, this operation will perform and
You need to compute the following expression: $x_1 \cdot y_1 + x_2 \cdot y_2 + \ldots + x_{2^k + 1} \cdot y_{2^k + 1}$, where is the number of set bits in the -th number, and is the number of zero bits in the -th number.
denotes the bitwise exclusive OR of numbers and
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers (, ) — the length of the binary numbers and the number determining the number of binary numbers in the sequence.
The second line of each test case contains a binary string of length () — the value of .
The third line of each test case contains a binary string of length () — the value of .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output one integer — the value of the expression from the statement.
Note
In the first test case, the process was described in the statement. The resulting sequence of binary numbers is $[\texttt{010}, \texttt{110}, \texttt{100}, \texttt{010}, \texttt{110}]$. Then the expression in the statement equals $1 \cdot 2 + 2 \cdot 1 + 1 \cdot 2 + 1 \cdot 2 + 2 \cdot 1 = 10$.
In the second test case, at the first step we have $a_2 = a_1 \oplus a_3 = \texttt{0} \oplus \texttt{0} = \texttt{0}$. Therefore, the resulting sequence of numbers is . For it, the value of the expression is zero.
Samples
4
3 2
010
110
1 1
0
0
2 2
01
00
7 30
1010111
0011010
10
0
3
12169074016
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |