xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律

C. Magic Formulas
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

People in the Tomskaya region like magic formulas very much. You can see some of them below.

Imagine you are given a sequence of positive integer numbers p1, p2,
..., pn. Lets
write down some magic formulas:


Here, "mod" means the operation of taking the residue after dividing.

The expression  means
applying the bitwise xor (excluding "OR") operation to integers x and y.
The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in Pascal — by "xor".

People in the Tomskaya region like magic formulas very much, but they don't like to calculate them! Therefore you are given the sequence p, calculate the
value of Q.

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 106).
The next line contains n integers: p1, p2, ..., pn (0 ≤ pi ≤ 2·109).

Output

The only line of output should contain a single integer — the value of Q.

Sample test(s)
input
3
1 2 3
output
3

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; int XOR[1100000]; int main()
{
int ans=0,n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int p;
scanf("%d",&p);
ans^=p;
}
for(int i=1;i<=n-1;i++)
{
XOR[i]=XOR[i-1]^i;
int len=i+1;
int res=n%(len*2);
if(res>=len)
{
ans^=XOR[i];
res-=len;
}
ans^=XOR[res];
}
printf("%d\n",ans);
return 0;
}

Codeforces 424 C. Magic Formulas的更多相关文章

  1. CodeForce 424C Magic Formulas

    这个题就是求出给的公式的结果. 仅仅要知道异或运算满足交换律跟结合律即可了.之后就是化简公式. #include<map> #include<string> #include& ...

  2. codeforce-424C. Magic Formulas(数学)

    C. Magic Formulas time limit per test:2 seconds     memory limit per test:256 megabytes   input stan ...

  3. codeforces C. Magic Formulas 解题报告

    题目链接:http://codeforces.com/problemset/problem/424/C 题目意思:给出 n 个数:p1, p2, ..., pn,定义: q1 = p1 ^ (1 mo ...

  4. Codeforces Round #242 (Div. 2) C. Magic Formulas

    解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...

  5. Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)

    题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1.  交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...

  6. cf C. Magic Formulas

    http://codeforces.com/contest/424/problem/C #include <cstdio> #include <cstring> #includ ...

  7. Codeforce 424C Magic Formulas 找规律

    题目链接:http://codeforces.com/contest/424/problem/C 题意:求Q值 思路:找规律 显然能够得到一个矩阵 把这个矩阵画出来就能发现一个横向的规律和一个主对角线 ...

  8. 【Codeforces 1110E】Magic Stones

    Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转 ...

  9. codeforces 710C C. Magic Odd Square(构造)

    题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in ea ...

随机推荐

  1. 二段式fsm

    1.推荐在敏感表下的默认状态为X,这样描述的好处有2个: 好处1:仿真易观察bug. 好处2:综合对不定态X的处理是"Don't Care",即任何没有定义的状态寄存器向量都会被忽 ...

  2. Python旅途——入门基础

    1.入门 ​ 作为近几年计算机程序设计语言中很火的Python,是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大 ...

  3. linux系统,python3.7环境安装talib过程

    获取源码wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 解压进入目录tar -zxvf ta-lib-0. ...

  4. css 标题

    纯CSS制作的复古风格的大标题 .vintage{ background: #EEE url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAA ...

  5. soa服务治理

    SOA服务治理 文章:SOA 治理简介 文章:中小型互联网公司微服务实践-经验和教训

  6. 【Luogu】P1131时态同步(树形DP)

    题目链接 甚矣吾衰也!这么简单的DP我都不会了 太恐怖了 树形DP,从子树里选出时间最长的来,剩下的调到这个最长时间即可. #include<cstdio> #include<cct ...

  7. 在 Linux 实例上自动安装并运行 VNC Server

    原文网址:https://help.aliyun.com/knowledge_detail/41181.html?spm=5176.8208715.110.11.4c184ae8mlC7Yy 您可以使 ...

  8. STL学习笔记(三) 关联容器

    条款19:理解相等(equality)和等价(equivalence)的区别 相等的概念是基于 operator== 的,如果 operator== 的实现不正确,会导致并不实际相等等价关系是以&qu ...

  9. 将RabbitMq用好需要了解的一些基础知识

    本文面向有一定RabbitMq基础的童鞋. 首先,我们来理理RabbitMq的一些基本概念: Connection: 客户端与RabbitMq服务器节点的Tcp链接. Channel: 信道,因为一条 ...

  10. 使用Eclipse+axis2一步一步发布webservice

    1.下载axis2相关软件http://axis.apache.org/axis2/java/core/download.html 2.Java环境配置:JAVA_HOME.JRE_HONE.PATH ...