题目链接

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≤2^30−1).

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,然后要求出数组b,数组b于数组a之间满足这样的规律:

b[i]=a[1]a[2]·····^a[i].

像这样的话其实是很简单的,但是我们并不是要求第一次异或得出的数组b,而是要求经过m次异或之后得出的数组b。

分析:

首先找一下规律:(都与最原始的a数组进行比较)

异或第一次的时候:

每一项相当于都把它前面的任意的一项全部都异或上了。

然后再观察异或第二次的时候:

相当于每一项都是差项异或,异或上前面所有的中与它本身相差两项、四项、六项、八项····等等。

异或第三次的时候:

相当于每一项都是差项异或,异或上前面所有的中与它本身相差一项、四项、五项、八项····等等。

然后总结下规律就是:

把每次变换的系数记录下来后可以发现是个杨辉三角,第x次变换第y项是C(x+y-2,y-1);

C(n,m),如果n&m==m则C(n,m)为奇数,考虑第一项对后面每一项的贡献是奇数还是偶数,

依次类推后面的项数产生的贡献情况

代码:

#include <iostream>
#include <cstdio>
#include<string.h>
using namespace std;
const int N = 2e6+10;
int a[N], b[N];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d %d", &n, &m);
memset(b,0,sizeof(b));
for(int i=1; i<=n; i++)
{
scanf("%d", &a[i]);
}
for(int i=1; i<=n; i++)///第m次异或第i项的时候
{
int nn=m+i-2,mm=i-1;
if((nn&mm)==mm)
{
for(int j=i; j<=n; j++) b[j]^=a[j-i+1];
}
}
for(int i=1; i<=n; i++) printf("%d%c",b[i],i==n?'\n':' ');
}
return 0;
}

2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  2. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  3. 2017ACM暑期多校联合训练 - Team 6 1010 HDU 6105 Gameia (博弈)

    题目链接 Problem Description Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes ...

  4. 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)

    题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...

  5. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  6. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  7. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  8. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  9. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

随机推荐

  1. Markdown github 风格语法

    某些效果cnblog无法支持,见 https://github.com/tanghammer/note/blob/master/Markdown%20github%E9%A3%8E%E6%A0%BC% ...

  2. Dsyy的第一篇博文~

    2017-08-07  周一  晴热热热热热 咳咳,很多人看到dsyy第一反应是什么意思?当然是大神媛媛!显然不是些(diao)(si)yy.(da)(si)yy...的别义,咋有点此地无银三百两的感 ...

  3. 软工网络15团队作业4-DAY4

    每日立会 昨天的工作. 张陈东芳:sql语句存储商品信息 吴敏烽:调试获取商品信息的方法 周汉麟:根据商品编号来获取商品资料方法调试 林振斌:输出最近浏览记录的方法检查 李智:cookies的检查 全 ...

  4. Objective - C 之延展

    延展:为已有的类新增私有方法,只能在本类中使用 一.创建过程: 二.总结: 1.延展只有.h文件,在其中写新方法的声明,在原本的类(Person)中写方法的实现: 2.上述的方法其实很不安全,因为如果 ...

  5. CSS布局-垂直居中问题

    在前端页面的布局方面,很多时候需要用到垂直居中,如果父集元素或子元素的高度是固定的那么垂直居中可以用line-height或者定位 top:50%:margin-top:- height/2 px:实 ...

  6. 【JavaScript】BOM

    一.前言        接着前一章的内容,继续Js的学习. 二.内容 window对象 //确定窗口位置 var leftPos = (typeof window.screenLeft == &quo ...

  7. BZOJ2006:[NOI2010]超级钢琴——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2006 https://www.luogu.org/problemnew/show/P2048#su ...

  8. Zabbix Agent for Linux部署(四)

    一.环境介绍 二.代理安装 1.将代理程序拷贝至Node1服务器的/usr/src/zabbix3.4.5/目录下 [root@Node3 zabbix3.-.el7.x86_64.rpm zabbi ...

  9. Jenkins远程代码执行漏洞检查(CVE-2017-1000353)

    Jenkins的反序列化漏洞,攻击者使用该漏洞可以在被攻击服务器执行任意代码,漏洞利用不需要任何的权限 漏洞影响范围: 所有Jenkins主版本均受到影响(包括<=2.56版本)所有Jenkin ...

  10. 温习classList api

    有道题是一个removeClass的功能,代码里是正则分隔了传入的name,根据name的个数,循环移除掉,让寻找bug..看了了这几行代码,首先想到的是我会如何去优化. 如果看代码一两分钟就能找到公 ...