Codeforces Arpa’s obvious problem and Mehrdad’s terrible solution
//I am struggling
//Just Not Good at it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef map<int, int>mpii;
const int mod = 1000007;
const int high = 100003;
int ar[high];
int main()
{
fast;
int n , x , i , j ;
LL p , res=0;
mpii mp;
while(cin >> n >> x)
{
mp.clear();
for(i=1; i<=n; i++)
{
cin >> ar[i];
mp[ar[i]]++;
}
// for(i=1; i<=n-1; i++)
// {
// for(j=i+1; j<=n; j++)
// {
// if((ar[i] ^ ar[j]) == x)
// {
// cout << ar[i] << "^" << ar[j] << "=" << (ar[i] ^ ar[j]) << "\n";
// }
// }
// }
res=0;
for(i=1; i<=n; i++)
{
p = x ^ ar[i];
res+=mp[p];
if(p == ar[i]) res--;
}
cout << res / 2 << "\n";
}
return 0;
}
//Just Not Good at it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef map<int, int>mpii;
const int mod = 1000007;
const int high = 100003;
int ar[high];
int main()
{
fast;
int n , x , i , j ;
LL p , res=0;
mpii mp;
while(cin >> n >> x)
{
mp.clear();
for(i=1; i<=n; i++)
{
cin >> ar[i];
mp[ar[i]]++;
}
// for(i=1; i<=n-1; i++)
// {
// for(j=i+1; j<=n; j++)
// {
// if((ar[i] ^ ar[j]) == x)
// {
// cout << ar[i] << "^" << ar[j] << "=" << (ar[i] ^ ar[j]) << "\n";
// }
// }
// }
res=0;
for(i=1; i<=n; i++)
{
p = x ^ ar[i];
res+=mp[p];
if(p == ar[i]) res--;
}
cout << res / 2 << "\n";
}
return 0;
}
Comments
Post a Comment