题目描述
未知整数数组 arr 由 n 个非负整数组成。
经编码后变为长度为 n−1 的另一个整数数组 encoded,其中 encoded[i]=arr[i]⊕arr[i+1](⊕ 表示按位异或运算)。
例如,arr=[1,0,2,1] 经编码后得到 encoded=[1,2,3]。
现在给定编码后的数组 encoded 和原数组的第一个元素 first(即 arr[0]),请解码并返回原数组 arr。可以证明答案存在且唯一。
输入格式
第一行两个整数 n 和 first,其中 n 表示原数组 arr 的长度,first 表示 arr[0] 的值。
第二行 n−1 个整数,表示编码后的数组 encoded。
输出格式
一行 n 个整数,表示解码后的原数组 arr,整数之间用空格分隔。
样例 #1
样例输入 #1
4 1
1 2 3
样例输出 #1
1 0 2 1
样例 #2
样例输入 #2
5 4
6 2 7 3
样例输出 #2
4 2 0 7 4
说明/提示
样例解释
样例 1:若 arr=[1,0,2,1],则 first=1,且 $encoded = [1 \oplus 0,\ 0 \oplus 2,\ 2 \oplus 1] = [1,2,3]$,与输入一致。
样例 2:若 arr=[4,2,0,7,4],则 first=4,且 $encoded = [4 \oplus 2,\ 2 \oplus 0,\ 0 \oplus 7,\ 7 \oplus 4] = [6,2,7,3]$,与输入一致。
数据范围
- 对于 20% 的数据,满足 2≤n≤20,0≤encodedi,first≤103。
- 对于 100% 的数据,满足 2≤n≤104,0≤encodedi,first≤105。
保证 encoded 的长度为 n−1。