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. CSS3-弹性盒模型-FlexBox

    Flex容器属性 display 定义一个Flex容器,根据其取的值来决定是内联还是块.Flex容器会为其内容建立新的伸缩格式化上下文. .container { display: flex; /* ...

  2. docker apache安装

    文章来源: 1.添加镜像 # docker pull httpd2. 2.创建httpd文件 # mkdir /data/httpd2. 3.启动apache # docker run -it -p ...

  3. python-数字类型内置方法

    数字类型内置方法 为什么要有数据类型? 数据是用来表示状态的,不同的状态就应该用不同的数据类型去表示 整型(int) 用途:年龄.号码.银行卡号等 定义:可以使用int()方法将纯数字的字符串转换为十 ...

  4. restful规范和drf模块

    restfu1规范 它是一个规范,面向资源架构 10条规范: 1.api与用户的通信协议,总是使用https协议 api网上提供的接口 2.域名: 尽量将api部署在专用域名(会存在跨域问题) API ...

  5. logging日志模块,四种方式

    1.最简单的用法 import logging logging.error("hah") logging.info("hah") logging.debug(& ...

  6. requests库的学习——跟随官方文档

    发送GET请求: import requests r=requests.get("http://www.kekenet.com/") 如果需要传递参数可以有以下几种方法: impo ...

  7. 菜鸟的《Linux程序设计》学习—shell script

    1. 认识shell script shell script是利用shell的功能缩写的一个"程序",这个程序是使用纯文本文件,将一些shell的语法与命令(含外部命令)写在里面, ...

  8. Spring,Mybatis,Springmvc框架整合项目(第三部分)

    一.静态资源不拦截 第二部分最后显示的几个页面其实都加载了css和js等文件,要不然不会显示的那么好看(假装好看吧),前面已经说了,我们在web.xml中配置了url的拦截形式是/,那么Dispatc ...

  9. nw335 debian sid x86-64 -- 4 realtek 提供的官方驱动

    realtek 提供的官方驱动   1 查看无线网卡的驱动芯片: $ sudo lsusb Bus 001 Device 003: ID 0bda:8176 Realtek Semiconductor ...

  10. Java列出接口实现的所有接口

    package com.tj; public class MyClass2 { public static void main(String[] args) { Class cls = java.ut ...