Codeforces 424 C. Magic Formulas
xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律
2 seconds
256 megabytes
standard input
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.
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).
The only line of output should contain a single integer — the value of Q.
3
1 2 3
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的更多相关文章
- CodeForce 424C Magic Formulas
这个题就是求出给的公式的结果. 仅仅要知道异或运算满足交换律跟结合律即可了.之后就是化简公式. #include<map> #include<string> #include& ...
- codeforce-424C. Magic Formulas(数学)
C. Magic Formulas time limit per test:2 seconds memory limit per test:256 megabytes input stan ...
- codeforces C. Magic Formulas 解题报告
题目链接:http://codeforces.com/problemset/problem/424/C 题目意思:给出 n 个数:p1, p2, ..., pn,定义: q1 = p1 ^ (1 mo ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas
解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1. 交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...
- cf C. Magic Formulas
http://codeforces.com/contest/424/problem/C #include <cstdio> #include <cstring> #includ ...
- Codeforce 424C Magic Formulas 找规律
题目链接:http://codeforces.com/contest/424/problem/C 题意:求Q值 思路:找规律 显然能够得到一个矩阵 把这个矩阵画出来就能发现一个横向的规律和一个主对角线 ...
- 【Codeforces 1110E】Magic Stones
Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转 ...
- 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 ...
随机推荐
- Django中模板查找路径配置
- shell-code-6-输入输出重定向
解释: 1. 文件描述符0通常是标准输入(STDIN,终端),1 是标准输出(STDOUT,终端),2 是标准错误输出(STDERR). 2. 如果希望 stderr 追加到 file 文件末尾,可以 ...
- iOS设置UINavigationBar 的样式
为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar UINavigationBar *bar = self.navigationController ...
- opencv中相关的矩阵运算
一.矩阵Mat I,img,I1,I2,dst,A,B;double k,alpha;Scalar s;1.加法I=I1+I2;//等同add(I1,I2,I);add(I1,I2,dst,mask, ...
- CodeForces 484B 数学 Maximum Value
很有趣的一道题,题解戳这. #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- Knockout v3.4.0 中文版教程-5-计算监控-使用计算监控
3. 计算监控 1.使用计算监控 如果你有一个监控的属性firstName和另一个lastName,但你想显示全名怎么办? 这就是引入计算监控的原因-这是依赖于一个或多个其他的observables函 ...
- 对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App)
对比使用Charles和Fiddler两个工具及利用Charles抓取https数据(App) 实验目的:对比使用Charles和Fiddler两个工具 实验对象:车易通App,易销通App 实验结果 ...
- OSPF 提升 一 ----基础
ospf ccnp内容 一 link-state protocols IGP 开放式的最短路径优先协议 公有协议 支持中到大型的网络 spf算法 链路状态协议 1. ...
- 转自kuangbin的AC自动机(赛前最后一博)
有了KMP和Trie的基础,就可以学习神奇的AC自动机了.AC自动机其实就是在Trie树上实现KMP,可以完成多模式串的匹配. AC自动机 其实 就是创建了一个状态的转移图,思想很 ...
- iOS学习笔记20-地图(二)MapKit框架
一.地图开发介绍 从iOS6.0开始地图数据不再由谷歌驱动,而是改用自家地图,当然在国内它的数据是由高德地图提供的. 在iOS中进行地图开发主要有三种方式: 利用MapKit框架进行地图开发,利用这种 ...