Untitled
unknown
plain_text
3 years ago
935 B
25
Indexable
public class Solution {
public int solve(ArrayList<Integer> A) {
int mod=(int)Math.pow(10,9)+7;
long ans=0;
for(int i=0;i<31;i++){
ArrayList<Integer> B=new ArrayList<>();
for(int j=0;j<A.size();j++){
if(((A.get(j)>>i)&1)==1){
B.add(1);
}
else{
B.add(0);
}
}
int size=B.size();
long sum=0;
int lastseen=B.size();
for(int k=B.size()-1;k>-1;k--){
if(B.get(k)==1){
lastseen=k;
sum=sum+(size-k);
}
else{
sum=sum+(size-lastseen);
}
}
long l=sum*(int)Math.pow(2,i);
ans=(ans%mod+l%mod)%mod;
}
return (int)ans;
}
}
Editor is loading...