Watchmen CodeForces - 650A

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula .

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.

Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Examples

Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11

Note

In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and  for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

题意:给出n个点的坐标(xi,yi);问有多少对点|xi-xj|+|yi-yj| == sqrt( (xi-xj)^2 + (yi-yj)^2 )。 注意:题中有些点的和重合的。

题解:map存存状态,加加减减就好了

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdlib>
#include <vector>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 1e5+;
const int mod = 1e9+; map<ll,ll>mpx;
map<ll,ll>mpy;
map<pair<ll,ll>,ll>mp;
int main()
{
mpx.clear();
mpy.clear();
mp.clear();
int n;
ll a,b,ans=,num=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lld %lld",&a,&b);
num+=mp[make_pair(a,b)];
mp[make_pair(a,b)]++;
ans+=mpx[a];
mpx[a]++;
ans+=mpy[b];
mpy[b]++;
//printf("%lld %lld\n",ans,num);
}
printf("%lld\n",ans-num);
return ;
}

Watchmen CodeForces - 650A的更多相关文章

  1. A. Watchmen(Codeforces 650A)

    A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  2. Codeforces 650A Watchmen

    传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...

  3. (水题)Codeforces - 650A - Watchmen

    http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...

  4. codeforces Codeforces 650A Watchmen

    题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...

  5. [刷题codeforces]650A.637A

    650A Watchmen 637A Voting for Photos 点击查看原题 650A又是一个排序去重的问题,一定要注意数据范围用long long ,而且在写计算组合函数的时候注意也要用l ...

  6. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

  7. Codeforces Round #345 (Div. 1) A. Watchmen

    A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  8. CodeForces 651C Watchmen map

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  9. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点

    Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...

随机推荐

  1. jdbc操作数据库的步骤

    package com.jckb; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepare ...

  2. 【Linux/Ubuntu学习 11】git查看某个文件的修改历史

    有时候在比对代码时,看到某些改动,但不清楚这个改动的作者和原因,也不知道对应的BUG号,也就是说无从查到这些改动的具体原因了- [注]:某个文件的改动是有限次的,而且每次代码修改的提交都会有commi ...

  3. Python高效开发实战——Django、Tornado、Flask、Twisted

    今天要推荐的就是这本书,内容涉及四种主流的Python Web开发框架,零基础完成网站搭建.数据库设计.前后端开发,全方位领悟Python原理与应用. 最新最全的框架实战,尽在这本书,可搜索亚马逊.京 ...

  4. HDU3954 线段树(区间更新 + 点更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3954 , 一道比较好的线段树题,值得做. 题目是NotOnlySuccess大神出的,借此题来膜拜一下 ...

  5. bzoj4622 [NOI 2003] 智破连环阵

    Description B国在耗资百亿元之后终于研究出了新式武器——连环阵(Zenith Protected Linked Hybrid Zone).传说中,连环阵是一种永不停滞的自发性智能武器.但经 ...

  6. 【BZOJ1101】[POI2007] Zap(莫比乌斯反演)

    点此看题面 大致题意: 求\(\sum_{x=1}^N\sum_{y=1}^M[gcd(x,y)==d]\). 一道类似的题目 推荐先去做一下这道题:[洛谷2257]YY的GCD,来初步了解一下莫比乌 ...

  7. 2dsphere索引

    概念:球面地理位置索引 创建方式: db.collection.ensureIndex({w:'2dsphere'}) wdspere中,位置的表示方式不再是简单的经度,纬度,数组,而是变成一种复杂的 ...

  8. 2018.6.24 oracle数据库的 事务及视图

    第06章 事务及视图 本章内容  事务  视图 1 事务 1.1 什么是事务 事务也称工作单元,是一个或多个SQL语句组成的序列,这些个SQL操作作为一个完整的工作单元要么全部执行,要么全不执行. ...

  9. 2018.6.21 css的应用---注册表格

    参与css样式表格的注册表单 <!DOCTYPE html> <head> <meta charset="UTF-8" /> <meta ...

  10. Deep Learning 优化方法总结

    Stochastic Gradient Descent (SGD) SGD的参数 在使用随机梯度下降(SGD)的学习方法时,一般来说有以下几个可供调节的参数: Learning Rate 学习率 We ...