Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1172 Accepted Submission(s): 682
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
Source
找出前缀异或m次形成的新序列b
这道题昨晚都不知道为毛有这种规律。。。。
1 2 3 第一次形成:1 3 0,第二次 : 1 2 2 第三次: 1 3 1
假如是1,2,3,4,可以先打表找出规律
题解中给出新的序列的系数值为杨辉三角的规律,也就是当前值等于上一次的递推值*前一个的当前值,用数组来讲就是dp[i][j]=dp[i-1][j]*dp[i][j-1];
这道题昨晚都不知道为毛有这种规律。。。。
1 2 3 第一次形成:1 3 0,第二次 : 1 2 2 第三次: 1 3 1
假如是1,2,3,4,可以先打表找出规律
for(int i=1;i<=100;i++)
{a1=a1;
a2^=a1;
a3^=a2;
a4^=a3;
a5^=a4;
printf("%d %d %d %d %d\n",a1,a2,a3,a4,a5);
}
题解中给出新的序列的系数值为杨辉三角的规律,也就是当前值等于上一次的递推值*前一个的当前值,用数组来讲就是dp[i][j]=dp[i-1][j]*dp[i][j-1];
这样在x&y==y时,也就是系数为奇数时能确定其价值
/**
by z_guibin
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define N 200500
int a[N],b[N];
int main()
{
/*int a1=1,a2=2,a3=3,a4=4,a5=5;
int s[100];
for(int i=1;i<=100;i++)
{
a1=a1;
a2^=a1;
a3^=a2;
a4^=a3;
a5^=a4;
printf("%d %d %d %d %d\n",a1,a2,a3,a4,a5);
}*/
int t;
int n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&m);
memset(b,0,sizeof(b));
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
int x=i+m-1;
int y=i;
if((x&y)==y)
{
for(int j=i;j<n;j++)
{
b[j]^=a[j-i];
}
}
}
for(int i=0;i<n-1;i++)
{
printf("%d ",b[i]);
}
cout<<b[n-1]<<endl;
}
return 0;
}