MZL‘s xor
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 208 Accepted Submission(s): 157
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
2 3 5 5 7 6 8 8 9
Sample Output
14 16
Source
2015 Multi-University Training Contest 5
可以发现,a[i]+a[j]和a[j]+a[i]是相同的,异或值为0,所以真正有贡献的就是两倍的本身。
#include<iostream> #include<cstdio> #include<cstring> #include<math.h> #include<algorithm> using namespace std; #define N 500005 typedef long long ll; ll a[N],b[N]; int len; int main() { int i,j,n,m,t; scanf("%d",&t); while(t--) { len=0; int z,l; scanf("%d%d%d%d",&n,&m,&z,&l); a[1]=0; for(i=2; i<=n; i++) a[i]=(a[i-1]*m+z)%l; int sum=a[1]; /* for(i=1;i<=n;i++) for(j=1;j<=n;j++) { b[len++]=a[i]+a[j]; } for(i=1;i<len;i++) { b[i]=b[i-1]^b[i]; } cout<<b[len-1]<<endl; */ for(i=2; i<=n; i++) { a[i]=a[i-1]^a[i]; } printf("%lld\n",a[n]*2); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-07 09:39:09