2015 Multi-University Training Contest-5 MZL's xor
2015-08-10 00:28
357 查看
2015 Multi-University Training
Contest-5
MZL's xor
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 688 Accepted Submission(s): 440
Problem Description
MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n)
The xor of an array B is defined as B1 xor B2...xor Bn
Input
Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:n,m,z,l
A1=0,Ai=(Ai−1∗m+z) mod l
1≤m,z,l≤5∗105,n=5∗105
Output
For every test.print the answer.
Sample Input
23 5 5 76 8 8 9
Sample Output
1416
分析:
问题的关键在i和j的取值上, (Ai+Aj)(1≤i,j≤n) 仔细阅读只要发现i和j的取值范围,只要在1~n之间都符合,并没有强调i和j需要满足某种关系,那么,凡是i!=j的情况,都会导致( Ai+Aj )与( Aj+Ai )想与产生零的情况,而其他任何数和零相与都不变,所以可以无视i!=j的所有情况,只需要计算所有的i==j的情况,并且全部相与即可得出答案。
#include<iostream>using namespace std; __int64 a[500005]; int main() { int t; cin >> t; while (t--) { int n, m, z, l, s = 0; cin >> n >> m >> z >> l; a[1] = 0; for (int i = 2; i <= n; i++) { a[i] =( (a[i - 1] * m) % l + z%l)%l; <span style="font-family: Arial, Helvetica, sans-serif;">s ^= a[i] + a[i];</span>
} cout << s << endl; } return 0; }
相关文章推荐
- hdu1022(Train Problem I)----- 典型栈类题目
- failed to load the jni shared library jvm
- 多图细数TurboMail邮件系统丰富的用户权限管理
- 跨时代产品,TurboMail邮件系统V7.0
- 解决mvn install问题Failure to find ** was cached in the local repository
- UltraISO制作U盘启动盘安装Win7/9/10系统攻略
- HDOJ 1022 Train Problem I (Stack)
- icloud无法注销,icloud服务中keyChain钥匙串无法关闭问题的解决。
- Codeforces 148E Porcelain (预处理+多重背包)
- ZOJ 3725 - Painting Storages(DP)
- leetcode 217 Contains Duplicate 数组中是否有重复的数字
- leetcode 217 Contains Duplicate 数组中是否有重复的数字
- hdu 1789 Doing Homework again 状态压缩DP
- 利用keychain保存iphone唯一识别码idfv
- 2015 HUAS Summer Trainning #4 D
- 2015 HUAS Summer Trainning #4 C
- whust #0.2 J Jailbreak (未AC)
- GenericKeychain
- 2015 HUAS Summer Trainning #4 B
- hnuoj 13375 Flowery Trails(SPFA)