I am trying to solve the problem by making a 32 bit array count which will store the no of subbarray having bit 1 at a certain index.for eg count[i] will store the no of subarrays(formed from n numbers) having bit 1 at the position i.And after obtaining that i multiplied it by 2 raised to the power i.And the way i am obtaining count array is first calculating the no of subarrays having 0 at that index.
But i am not able to find out error in my approach as i am getting a partial score of 10 out of 30.
My soln:-
Unable to pass all the test cases
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
lli n, tmp;
int idx[50];
int main(){
lli ans = 0; cin >> n;
for(int i=1; i<=n; ++i){
cin >> tmp;
for(int j=0; j<=31; ++j){
lli pw = 1l << j;
if(tmp & pw){
ans += pw * i;
idx[j] = i;
} else if(idx[j]){
ans += pw * idx[j];
}
}
}
cout << ans << endl;
return 0;
}