CF1713F.Lost Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
My orzlers, we can optimize this problem from O(S3) to O(T95) !
— Spyofgame, founder of Orzlim religion
A long time ago, Spyofgame invented the famous array a ( 1 -indexed) of length n that contains information about the world and life. After that, he decided to convert it into the matrix b ( 0 -indexed) of size (n+1)×(n+1) which contains information about the world, life and beyond.
Spyofgame converted a into b with the following rules.
- bi,0=0 if 0≤i≤n ;
- b0,i=ai if 1≤i≤n ;
- bi,j=bi,j−1⊕bi−1,j if 1≤i,j≤n .
Here ⊕ denotes the bitwise XOR operation.
Today, archaeologists have discovered the famous matrix b . However, many elements of the matrix has been lost. They only know the values of bi,n for 1≤i≤n (note that these are some elements of the last column, not the last row).
The archaeologists want to know what a possible array of a is. Can you help them reconstruct any array that could be a ?
输入格式
The first line contains a single integer n ( 1≤n≤5⋅105 ).
The second line contains n integers b1,n,b2,n,…,bn,n ( 0≤bi,n<230 ).
输出格式
If some array a is consistent with the information, print a line containing n integers a1,a2,…,an . If there are multiple solutions, output any.
If such an array does not exist, output −1 instead.
输入输出样例
输入#1
3 0 2 1
输出#1
1 2 3
输入#2
1 199633
输出#2
199633
输入#3
10 346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607
输出#3
725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365
说明/提示
If we let a=[1,2,3] , then b will be:
0 1 2 3 0 1 3 0 0 1 2 2 0 1 3 1 The values of b1,n,b2,n,…,bn,n generated are [0,2,1] which is consistent with what the archaeologists have discovered.