数星星
2025-07-18 18:37:54
发布于:浙江
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll x[100010],y[100010];
void solve(){
cin>>n;
map<ll,ll> mx;
map<ll,ll> my;
map<ll,ll> ml;
map<ll,ll> mr;
for(int i = 1;i <= n;i++){
cin>>x[i]>>y[i];
mx[x[i]]++;
my[y[i]]++;
ml[x[i]-y[i]]++;
mr[x[i]+y[i]]++;
}
ll ans = 0;
for(auto i:mx){
ans+=i.second*(i.second-1);
}
for(auto i:my){
ans+=i.second*(i.second-1);
}
for(auto i:ml){
ans+=i.second*(i.second-1);
}
for(auto i:mr){
ans+=i.second*(i.second-1);
}
cout<<ans<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
这里空空如也
有帮助,赞一个