Problem Link
#include <iostream>
using namespace std;
int main()
{
int t, n, odd, even;
cin >> t;
while(t--)
{
cin >> n;
int i,arr[n],freq[1100001]={0};
long res = 0;
odd = even = 0;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
freq[arr[i]]++;
}
for(int i = 0; i < n; i++)
{
if(arr[i] & 1)
{
odd++;
}
else
{
even++;
}
}
for(int i = 0; i < n; i++)
{
if(arr[i] % 2)
{
res += odd;
}
else
{
res += even;
}
res -= freq[arr[i] ^ 2];
res -= freq[arr[i]];
}
cout << res / 2 << endl;
}
}
#include <iostream>
using namespace std;
int main()
{
int t, n, odd, even;
cin >> t;
while(t--)
{
cin >> n;
int i,arr[n],freq[1100001]={0};
long res = 0;
odd = even = 0;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
freq[arr[i]]++;
}
for(int i = 0; i < n; i++)
{
if(arr[i] & 1)
{
odd++;
}
else
{
even++;
}
}
for(int i = 0; i < n; i++)
{
if(arr[i] % 2)
{
res += odd;
}
else
{
res += even;
}
res -= freq[arr[i] ^ 2];
res -= freq[arr[i]];
}
cout << res / 2 << endl;
}
}
Comments
Post a Comment