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 ...
随机推荐
- perl学习之:肯定匹配和否定匹配
tr/ / / 替换操作符不支持正则表达式 也不具备双引号替换能力m/ / s/ / / 都支持正则表达式,并且可以提供或限制双引号替换能力 $string = "25abc8" ...
- JavaScript正则表达式-反向引用
使用括号“()”进行分组,使子表达式(子模式)可以作为整体独立被修饰,子表达式所匹配的结果会被记录下来并可以单独被访问. /(a(b(cd){2})+)EF/ 则各引用分别对应: \1 对应(a(b ...
- 算法竞赛中c++一些需要注意的错误
1. 关于精度: 取整 除法取整: (除数为正)被除数为正时系统除法为向下取整,被除数为负时系统除法为向上取整. 向上取整(被除数非负,除数为正): 一般写法(有bug): int cal(int x ...
- jquery 元素文本取值/赋值
select元素选中option值 jq $("#select1 option:selected").text(); $("select id或class option: ...
- js--进阶知识点
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PYDay3-初识python
Python 种类 c.j.iron.ruby等,主要有三类:cpython.xxxpython.pypy 种类繁多我们精通一种即可 编译流程: py代码->字节码->机器码->计算 ...
- DDoS 攻击与防御:从原理到实践(上)
欢迎访问网易云社区,了解更多网易技术产品运营经验. 可怕的 DDoS 出于打击报复.敲诈勒索.政治需要等各种原因,加上攻击成本越来越低.效果特别明显等趋势,DDoS 攻击已经演变成全球性的网络安全威胁 ...
- 通过日志动态查看正在执行的mysql语句
通过日志动态查看正在执行的mysql语句 :tail -f /tmp/general_log.log
- zoj 1760 Doubles
Doubles Time Limit: 2 Seconds Memory Limit: 65536 KB As part of an arithmetic competency progra ...
- SPOJ GSS3 Can you answer these queries III ——线段树
[题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #inc ...