前言:这道题我们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;
}