In this HackerEarth Sherlock and XOR problem solution, You are given an array A1, A2...AN. You have to tell how many pairs (i, j) exist such that 1 ≤ i < j ≤ N and Ai XOR Aj is odd.
HackerEarth Sherlock and XOR problem solution.
#include <cstdlib>
#include <stdio.h>
#include <cstring>
#include <complex>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <utility>
#include <locale>
#include <sstream>
#include <string>
#include <istream>
#include <ostream>
#include<assert.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORI(i,a,n) for(i=a;i<n;i++)
#define FORC(it,C) for(it=C.begin();it!=C.end();it++)
#define scanI(x) scanf("%d",&x)
#define scanD(x) scanf("%lf",&x)
#define print(x) printf("%d\n",x)
#define ll long long
#define number32 4294967296ull
#define MAX 100001
#define len(s) s.length()
#define ff first
#define ss second
#define IN(A, B, C) (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
using namespace std;
typedef map<int,int> Mii;
typedef map<char,int> Mci;
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<int> vc;
typedef vector<ll> vl;
typedef map<int,int>::iterator Miii;
typedef map<char,int>::iterator Mcii;
ll A[MAX+1];
int main()
{
int t,i;
int n;
cin>>t;
AIN(t,1,10);
ll ceven,codd;
ll ans;
while(t--)
{
ceven=0;
codd=0;
cin>>n;
AIN(n,1,100000);
FOR(i,n)
{
cin>>A[i];
AIN(A[i],0,1000000000);
if(A[i]%2==0)
{
ceven++;
}
else codd++;
}
ans=ceven*codd;
cout<<ans<<endl;
}
return 0;
}
0 Comments