Partially Corrrect Answer..Plz Help..O(n) solution


#1

long long int mod=1000000007;
long long int calc(long long int x)
{
//long long int tp=((x%mod)((x+1)%mod))%mod;
return ((x
(x+1))/2ll)%mod;
}

int Solution::solve(vector &A) {
int n=A.size();
long long int ans=0,cnt=0,cnt0=0;
long long int uff=1;
for(long long int i=0;i<=30;i++)

{
    long long int j=0,cnt=0;
    while(j<n)
    {
        if((A[j]&(1ll<<i))==0)
        {
            cnt0=0;
            while(j<n && (A[j]&(1ll<<i))==0)
            {
                cnt0++;
                j++;
            }
            cnt=(cnt+(calc(cnt0)))%mod;
        
        }
        else
        j++;
        
    }
   // cout<<cnt<<" ";
   long long int tp=((calc(n)-cnt)*uff)%mod;
    ans=(ans+tp)%mod;
    uff*=2;
}
return ans;

}