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;
}
转载于:https://www.cnblogs.com/cxchanpin/p/6855510.html
Codeforces 424 C. Magic Formulas相关推荐
- Codeforces 424C Magic Formulas
题目链接:[这里写链接内容] (http://codeforces.com/contest/424/problem/C) 题面: C. Magic Formulas(神奇的矩阵) time limit ...
- 【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)
题干: Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degene ...
- 【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)
题干: This problem is given in two versions that differ only by constraints. If you can solve this pro ...
- (最小生成树)Codeforces Educational Codeforces Round 9 Magic Matrix
You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it i ...
- Codeforces 711B- Chris and Magic Square
B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- codeforces_#242 (Div. 2)
这个在codeforces的题目编号是424A-424E 424A,Squats 题目地址:http://codeforces.com/problemset/problem/424/A 题目意思: 就 ...
- the development of c language(转)
c语言之父Dennis Ritchie 写的关于c语言开发历史的文章,来自这里 lisp专家Richard P.Gabriel 的<the Rise of Worse is Better > ...
- java 平均值_Java求两个数平均值
如何正确的求2个数的平均值.在练习算法二分查找的时候发现的,以前没有注意到的bug 备注:数据以int类型为例 一.以前的通用写法 /** * 求a+b平均值 * @param a * @param ...
- 知乎上看到的一篇计算机发展史
1822 年,Charles Babbage 研发差分机(自动化算术).英国政府赞助. 1832 年,差分机只能完成 1/7. 1837 年,Charles Babbage 研发出一个电脑, Mech ...
最新文章
- poj 2482 Stars in Your Window(线段树+离散化+线扫描)
- C语言结构体对齐的不足
- 【Linux】一步一步学Linux——id命令(94)
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——struts.xml配置详情
- leetcode之回溯backtracing专题4
- cognos的HTMl显示,cognos利用html项目和提示元素结合
- Java实现简单的银行管理系统(最基本的功能/易上手)
- IBM要推POWER9,来了解一下POWER处理器的前世今生
- oo结尾的单词发音规律
- 2021-2025年中国共享Web托管服务行业市场供需与战略研究报告
- HDU 6045 Is Derek lying?
- mysql 1449 问题
- 彩色证件照片常用的红色、蓝色背景颜色值 1
- Rpm、Yum(程序包管理)
- 访问局域网计算机切换用户,图解“访问局域网中的电脑时提示输入帐号和密码”...
- CPU卡读写操作函数
- 在总账模块结账的时候提示总账和明细账对账不平结不了账
- java语言获取数据库中的表的总行数
- CGI跟FASTCGI区别
- pygame像素地图的实现