2017 Multi-University Training Contest - Team 7 1010 Just do it

27 篇文章 0 订阅

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


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 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(1T5) , denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1n2×105,1m109) .
The second line contains n nonnegative integers a1...n(0ai2301) .
 

Output
For each test case:
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);
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值