多校赛第七场1010 Just do it

[Poj 6129 Just do it](http://acm.hdu.edu.cn/showproblem.php?pid=6129)

###题解:
####官方题解(深奥, 看得我一知半解,恕我太菜,233~)

我的理解:
这题求前缀异或和,但由于要进行m次操作,所以完全暴力会T;
所以我们得找规律:
对于a[0],我们来看随着操作次数的变化,它对a[0] - a[n] 的贡献:

m/i12345678
111111111
212345678
31361015212836
4141020355684120

我们可以发现上表是一个扬辉三角形,从而可以归纳出对于a[0]在第m次操作时对其他数的贡献为C(m+i-2,i-1)(i = 1 时是对其本身的贡献 1<=i<=n)

因为是^,所以我们只需要判断C(x,y)的奇偶性,由lucas定理可知:当且仅当 x&y == y 时 C(x,y) 为奇数。

把i作为相对位置进行剪枝,优化算法。

AC代码:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
const int maxn = 2e5 + 10;
using namespace std;
typedef long long LL;
int n,m;
int a[maxn],b[maxn];
int main()
{
        int T;
        cin >> T;
        while(T--)
        {

                scanf("%d%d",&n,&m);
                for(int i = 0; i < n; i++)
                        scanf("%d",&a[i]);
                memset(b,0,sizeof(b));

                for(int i = 1; i <= n; i++)
                {
                       int y = m + i - 2;
                       int x = i - 1;
                       if((y&x) == x)
                       {
                               for(int j = i-1; j < n; j++)
                                       b[j] ^= a[j-i+1];
                       }
                }
                for(int i = 0; i < n; i++)
                        printf("%d%c",b[i],i==n-1? '\n':' ');
        }
        return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值