HDU 5344

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

HDU 5344的相关文章

hdu 5344 MZL&#39;s xor

MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 911    Accepted Submission(s): 589 Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to k

hdu 5344 MZL&#39;s xor(数学之异或)

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 inte

HDU 5344 MZL&#39;s xor (多校)[补7月28]

MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 249    Accepted Submission(s): 187 Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to k

HDU 5344(MZL&amp;#39;s xor-(ai+aj)的异或和)

MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 800    Accepted Submission(s): 518 Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to

hdu 5344 (多校联赛) MZL&#39;s xor --- 位运算

here:    首先看一下题吧:题意就是让你把一个序列里所有的(Ai+Aj) 的异或求出来.(1<=i,j<=n) 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 B

HDU 5344(2015多校5)-MZL&#39;s xor(水题)

题目地址:HDU 5344 题意:求所有(Ai+Aj)的异或值. 思路:可以发现(Ai+Aj)和(Aj+Ai)的异或值为0,所以最后只剩下(Ai+Ai). #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm>

HDU 5344 MZL&#39;s xor(水题)

MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 456    Accepted Submission(s): 322 Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to

HDU 5344 多个数的和异或-思维-(位运算)

题意:n个数的两两做和,然后异或 分析: 异或的性质:两个相同的数异或为0,所以Ai+Aj异或Aj+Ai等于0,所以最终结果就是Ai+Ai的异或 代码: #include<stdio.h> long long t,n,m,z,l; long long a[1000005]; int main() { scanf("%I64d",&t); while(t--){ scanf("%I64d%I64d%I64d%I64d",&n,&m,

hdu 5344 简单题

很显然,i和j不同时,A[i]+A[j]会被异或两次,也就是没有异或.所以只要把每个数的二倍异或一遍(或者异或一遍最后乘2)就可以得到答案. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 typedef long long ll; 7 int n, m, z, l; 8 9 void init() 10 { 11 int pre = 0,