G. The Morning Star
- 思路:用map记录x,y,以及y-x、y+x
- 从前往后统计一遍答案即可
- 公式
- 是统计坐标轴方向的,-2倍是需要把本身这个点给减去容斥是减一倍,这里还需要把自己给挖掉
- 是统计对角线方向的。这也是一种常用的表示对角线的技巧
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define _for(i, a, b) for(int i=(a); i<(b); ++i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define vi vector<int>
using namespace std;
const int maxn = 2e5 + 10;
pii a[maxn];
void solve() {
int n;
cin>>n;
map<int,int>cntx,cnty,cntd,cnts;
map<pii,int>cnt;
int ans=0;
rep(i,1,n){
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+1+n);
rep(i,1,n){
int x=a[i].x,y=a[i].y;
ans+=cntx[x];
ans+=cnty[y];
ans-=2*cnt[{x,y}];
ans+=cntd[y-x];
ans+=cnts[y+x];
cntx[x]+=1;
cnty[y]+=1;
cntd[y-x]+=1;
cnts[y+x]+=1;
cnt[{x,y}]+=1;
}
cout<<ans*2<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _;
cin >> _;
while (_--)
solve();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署