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.

思路:结果就是计算同一横坐标、纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下)

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ll long long
ll a,b;
map<ll,ll> mp1;
map<ll,ll> mp2;
map< pair<ll,ll>,ll> mp;
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF){
ll ans=,num=;
mp1.clear();
mp2.clear();
mp.clear();
for(int i=;i<=n;i++){
scanf("%lld%lld",&a,&b);
num+=mp[make_pair(a,b)];
mp[make_pair(a,b)]++;
if(mp1.find(a)==mp1.end())
mp1[a]=;
else {
ans+=mp1[a];
mp1[a]++;
}
if(mp2.find(b)==mp2.end())
mp2[b]=;
else {
ans+=mp2[b];
mp2[b]++;
}
}
printf("%lld",(ll)ans-num);
}
return ;
}

CodeForces - 651C Watchmen (去重)的更多相关文章

  1. codeforces 651C Watchmen

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

  2. CodeForces 651C Watchmen map

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

  3. Codeforces 651C Watchmen【模拟】

    题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...

  4. codeforces 651C(map、去重)

    题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...

  5. 【CodeForces - 651C 】Watchmen(map)

    Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...

  6. Codeforces 650A Watchmen

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

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

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

  8. CodeForces 651C

    Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg s ...

  9. codeforces Codeforces 650A Watchmen

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

随机推荐

  1. Gridview的stretchMode等属性详解

    <GridView android:id="@+id/grid"android:layout_width="fill_parent"android:lay ...

  2. MyEclipse10下载安装破解及汉化内含jdk8u241及其帮助文档

    下载MyEclipse10以及破解包 MyEclipse10: 提取码:020c 破解包 提取码:mycj 注:破解包内含有破解教程,很详细,这里就不多说了 MyEclipse10汉化 操作系统:wi ...

  3. 分形的奥秘!分形着色器!shader 编程入门实战 ! Cocos Creator!

    极致的数学之美! 什么是分形? "一个粗糙或零碎的几何形状,可以分成数个部分,且每一部分都(至少近似地)是整体缩小后的形状" 简单来说,分形(fractal)就像这个doge表情包 ...

  4. 解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题

    最近把一个项目从core2.2迁移至core3.1,在本地win上跑没有问题,但是上线到生产Ubuntu docker环境下连接不上sqlserver报以下错误. A connection was s ...

  5. Java日志介绍(3)-Logback

    Logback 继承自Log4j,它建立在有十年工业经验的日志系统之上.它比其它所有的日志系统更快并且更小,包含了许多独特并且有用的特性. 1.配置 1.1.加载配置 Logback能够在初始化期间自 ...

  6. C++ Primer抄书笔记(二)——变量和基本类型(下)

    四.const限定符[引用/指针/顶层/常量表达式] const对象值不变,必须初始化,能完成此type的大部分operation. 一般,多文件独立变量,编译初始化仅文件内有效: 除非,(条件:初值 ...

  7. AndroidStudio修改默认C盘配置文件夹(.android.gradle.AndroidStudio)以及修改后避免踩的坑

    场景 AndroidStudio下载安装教程(图文教程): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103672471 在上 ...

  8. 解决MySql客户端秒退(找不到my.ini)

    问题说明(环境:windows7,MySql8.0) 今天安装好MySql后启动MySql服务-->启动服务都失败的就不要往下看了,自行百度解决. 打开客户端秒退,但在cmd中是可以使用数据库的 ...

  9. centos7系统启动流程

    前提:pc主机,MBR架构 第一步:post(power on system test)加电自检. pc机的主板上有个rom芯片(CMOS),加电后,cpu去找这个raw,然后读取里面的指令,检测机器 ...

  10. 黑龙江大学图书馆抢座python

    2019.11.01 增加成功发送QQ邮件. 2019.10.31更新 晚上测试成功 ========================== 昨晚肝了一晚上,今天已经写出成品并且部署到服务器上了,代码很 ...