Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1415 Accepted Submission(s): 826
Problem Description
There is a nonnegative integer sequence
a1...n
of length
n
. HazelFan wants to do a type of transformation called prefix-XOR, which means
a1...n
changes into
b1...n
, where
bi
equals to the XOR value of
a1,...,ai
. He will repeat it for
m
times, please tell him the final sequence.
Input
The first line contains a positive integer
T(1≤T≤5)
, denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1≤n≤2×105,1≤m≤109) .
The second line contains n nonnegative integers a1...n(0≤ai≤230−1) .
For each test case:
The first line contains two positive integers n,m(1≤n≤2×105,1≤m≤109) .
The second line contains n nonnegative integers a1...n(0≤ai≤230−1) .
Output
For each test case:
A single line contains n nonnegative integers, denoting the final sequence.
A single line contains n nonnegative integers, denoting the final sequence.
Sample Input
2 1 1 1 3 3 1 2 3
Sample Output
1 1 3 1解:列出某个序列异或3次 就能发现其系数满足杨辉三角,这样我们就能够知道 异或m次时他们的所有系数,如图:上代码:#include <iostream> #include <string.h> using namespace std; typedef long long ll; const int maxn=2e5+10; ll a[maxn]; ll b[maxn]; int main() { int t,n,m; cin>>t; while (t--) { memset(b,0,sizeof(b)); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%lld",&a[i]); int y=m-1; for (int i=1;i<=n;i++) { int x=m+i-2; if ((x&y)==y) { for (int j=i;j<=n;j++) b[j]=b[j]^a[j-i+1]; } } for (int i=1;i<=n;i++) if (i==1) printf("%lld",b[i]); else printf(" %lld",b[i]); printf("\n"); } return 0; }