传送门
首先题目要求求出数组内两两异或和
考虑到异或的性质,我们可以枚举二进制里面的每一位里面出现0和1的次数
例如样例1中
第一个二进制位出现了1次0和2次1
第二个二进制位出现了1次0和2次1
那么结果就是(1<<0)*1*2+(1<<1)*1*2
类似于这样的做法
从而判断这一位所在的数字被加了多少次
加的次数就相当于0出现的次数与1出现的次数的乘积
最后结果取模输出即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/************************************************************************* >>> Author: WindCry1 >>> Mail: lanceyu120@gmail.com >>> Website: https://windcry1.com >>> Date: 12/20/2019 2:28:02 AM *************************************************************************/ #include <cstring> #include <cmath> #include <cstdio> #include <cctype> #include <cstdlib> #include <ctime> #include <vector> #include <iostream> #include <string> #include <queue> #include <set> #include <map> #include <algorithm> #include <complex> #include <stack> #include <bitset> #include <iomanip> #include <list> #include <sstream> #include <fstream> #if __cplusplus >= 201103L #include <unordered_map> #include <unordered_set> #endif #define ll long long #define ull unsigned long long #define DEBUG(x) cout<<#x<<" : "<<x<<endl; #define lowbit(x) x&(-x) #define ls(u) u<<1 #define rs(u) u<<1|1 using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const double clf = 1e-8; const int MMAX = 0x7fffffff; const int INF = 0x3f3f3f3f; const ll mod = 1e9+7; const int dir[4][2]={-1,0,1,0,0,-1,0,1}; ostream& operator <<(ostream &out, pii &p){ return out<<p.first<<" "<<p.second; } istream& operator >>(istream &in, pii &p){ return in>>p.first>>p.second; } int cnt[70]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt"); //ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt"); ll n,t;cin>>n; for(int i=0;i<n;i++) { cin>>t; for(int j=0;j<62;j++) cnt[j]+=t&(1LL<<j)?1:0; } ll res=0; for(int i=0;i<62;i++){ res=(res+(((cnt[i]%mod*((n-cnt[i])%mod))%mod)*((1LL<<i)%mod))%mod)%mod; } cout<<res%mod<<endl; return 0; } |
2019-12-26 13:35 Author: WindCry1
0 条评论