Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 745 Accepted Submission(s): 429
Total Submission(s): 745 Accepted Submission(s): 429
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
b 1...n
, where
b i
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
题意:求a序列后m次xor前缀和
思路:通过对1位置对每个位置的贡献打表发现
第一次 贡献为 1 1 1 1 1 1 1 1 1 1 1
第二次 贡献为 1 0 1 0 1 0 1 0 1 0 1 0
第四次 贡献为 1 3个0 1 3个0 1 3个0 1 3个0
第八次 贡献为 1 7个0 1 7个0 1 7个0 1 7个0
#include<bits/stdc++.h>
using namespace std;
#define mem(a,x) memset(a,x,sizeof a)
#define rep(i,n) for (int i=0;i<n;i++)
#define lp(i,l,r) for (int i=l;i<=r;i++)
#define rlp(i,r,l) for (int i=r;i>=l;i--)
#define T_T for (int _=RD(),test=1;test<=_;test++)
typedef long long ll;
typedef double db;
const db eps = 1e-80;
const int MAXN = 2 * 1e5 + 10000;
const ll M = 1e9 + 7;
const char movech = 'a';
const int SIZE = 28;
int Scan()
{
int res = 0, flag = 0;
char ch;
if ((ch = getchar()) == '-')
{
flag = 1;
}
else if (ch >= '0' && ch <= '9')
{
res = ch - '0';
}
while ((ch = getchar()) >= '0' && ch <= '9')
{
res = res * 10 + (ch - '0');
}
return flag ? -res : res;
}
void Out(int a)
{
if (a < 0)
{
putchar('-');
a = -a;
}
if (a >= 10)
{
Out(a / 10);
}
putchar(a % 10 + '0');
}
void print_arr(int a[], int len)
{
lp(i, 1, len)
{
Out(a[i]);
if (i != len)
{
printf(" ");
}
}
printf("\n");
}
ll po[30];
void init()
{
po[0] = 1;
lp(i, 1, 25) po[i] = 2 * po[i - 1];
}
bool fin(ll n, ll m)
{
for (int i = 0; po[i] <= n; i++)
{
if ( (n & po[i]) && ( (m + po[i] - 1) / po[i]) % 2 == 0 )
{
return 0;
}
}
return 1;
}
int a[MAXN], b[MAXN];
int main()
{
init();
int T;
T = Scan();
while (T--)
{
int n = Scan(), m = Scan();
lp(i, 1, n)
{
a[i] = Scan();
}
mem(b, 0);
lp(i, 0, n)
{
if (fin(i, m))
for (int j = 1; j + i <= n; j++)
{
b[j + i] ^= a[j];
}
}
print_arr(b, n);
}
}