➤ Problem Link : 650A. Watchmen
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n,x,y; cin>>n; unordered_map<ll,ll> xmp,ymp; map<pair<ll,ll>, ll > st; for(int i=0;i<n;i++) { cin>>x>>y; xmp[x]++; ymp[y]++; st[make_pair(x,y)]++; } long double cnt=0; for(auto it=xmp.begin();it!=xmp.end();it++) cnt+=((it->second)*(it->second-1))/2; for(auto it=ymp.begin();it!=ymp.end();it++) cnt+=((it->second)*(it->second-1))/2; for(auto it=st.begin();it!=st.end();it++) cnt-=((it->second)*(it->second-1))/2; cout<<(ll)cnt; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!