include <bits/stdc++.h>
using namespace std;
long long int powe (int n){
if(n==0)return 1;
if(n==1)return 2;
if(n%2)return 2* (powe(n/2)*powe(n/2));
return (powe(n/2)*powe(n/2));
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr[n],even=0,odd=0;
long long int sum = 0,ans=0;
for(int i=0;i<n;i++){
cin>>arr[i];
if(arr[i]%2==0)even++;
else odd++;
sum+=arr[i];
}
if(sum%2){
int temp = odd;
odd--;
even+=odd/2;
ans+=powe(even)*temp;
}
else{
even+=odd/2;
ans+=powe(even);
}
cout<<ans<<endl;
}
return 0;
}
@learner84
Actually whats the question demands is that u have to find the number of subarrays after the removal of indexes having only even numbers or empty subarray.
This is the code i have coded. Its quite easy to understand.
include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
int cnt=0,ch=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]%2==0)
{
cnt++;
}
else
ch=1;
}
long long int ans=1;
for(int i=0;i<cnt;i++)
{
ans=(ans*2)%1000000007;
}
if(!ch)
ans–;
cout<<ans<<endl;
}
return 0;
}
the logic is what we aim for subarrays having even numbers so we count the even numbers and calculate its (power of 2) to generate all possibilities. but there is a case in which one possibility has to be subtracted and this is the case when all the numbers in an array are even . In this case answer would be their (power of 2) -1.