补一发xor和题解

前言:这道题我们icpc上有,我一直第三组数据错,一度怀疑到是不是我的算法有问题,今天浙江工业(差点高考被我妈安排去这个学校,结果我强烈要求出省读211),笑死了,一模一样的可以说相识度99.9%,不过它的submit太卡,唐克直接安排我们下班。

后来赛后问川哥,我1<<i,爆long long,要1 LL<<i;我知道以后当初去世。

We have N integers. The i-th integer is Ai.
Find  modulo (109+7).
What is  XOR ?
The XOR of integers A and B, A XOR B, is defined as follows:
When A XOR B is written in base two, the digit in the 2k's place (k≥0) is 1 if either A or B, but not both, has 1 in the 2k's place, and 0 otherwise.
For example, 3 XOR 5=6. (In base two: 011 XOR 101=110.)

Constraints
·2≤N≤3×105
·0≤Ai<260
·All values in input are integers.

输入

Input is given from Standard Input in the following format:

N
A1 A2 ... AN

输出

Print the value   modulo (109+7).

样例输入 Copy

【样例1】
3
1 2 3
【样例2】
10
3 1 4 1 5 9 2 6 5 3
【样例3】
10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

样例输出 Copy

【样例1】
6
【样例2】
237
【样例3】
103715602

提示

样例1解释
We have (1 XOR 2)+(1 XOR 3)+(2 XOR 3)=3+2+1=6.
样例3解释
Print the sum modulo (109+7).

直接发题解,不解释,要看的也可以看我的另一个

https://blog.csdn.net/m0_61949623/article/details/123186634?spm=1001.2014.3001.5501,完成一模一样的意思,相识度90%++;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[105];
ll sum;
ll length;
const int mod=1e9+7;
int main()
{
    ll n;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        ll b,len=0;
        scanf("%lld",&b);
        while(b)
        {
            if(b&1)a[len]++;
            b=b>>1;
            len++;
        }
        length=max(len,length);
    }
    for(int i=0;i<length;i++)
    {
        sum=(sum+(((((1ll<<i)%mod)*a[i]%mod)*(n-a[i])%mod))%mod);
    }
    printf("%lld",sum%mod);



   return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值