Atcoder Beginner Contest 147D

Each number on the each bit binary numbers taken out, in which the number N is a number of 0 is multiplied by a number which is required when a direct answer to this is then multiplied by a power of two, Note that all places may be spilled on the mod modulo.

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 long long a[300007];
 5 int num[300007][67];
 6 long long sum0[67],sum1[67],presolve[67];
 7 const long long mod = 1e9+7;
 8 int main(){
 9     ios::sync_with_stdio(false);
10     cin.tie(NULL);
11     cout.tie(NULL);
12     int n;
13     cin>>n;
14     for(int i=1;i<=n;++i)
15         cin>>a[i];
16     for(int i=1;i<=n;++i){
17         long long temp=a[i];
18         int cnt=0;
19         while(temp){
20             if(temp&1)
21                 num[i][cnt]=1;
22             ++cnt;
23             temp/=2;
24         }
25     }
26     long long ans=0;
27     for(int i=1;i<=n;++i){
28         for(int k=0;k<=60;++k){
29             if(num[i][k]==0)
30                 ++sum0[k];
31             else
32                 ++sum1[k];
33         }
34     }
35     long long x=1;
36     presolve[0]=1;
37     for(int i=1;i<=60;++i){
38         x*=2;
39         presolve[i]=x;
40     }
41     for(int i=0;i<=60;++i){
42         ans+=(((sum0[i]*sum1[i])%mod)*(presolve[i]%mod))%mod;
43          years% = mod;
44      }
 45      cout << years;
46      return  0 ;
47 }

Guess you like

Origin www.cnblogs.com/ldudxy/p/12076864.html