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. Babel配置中的presets、plugins、各个阶段stage的含义

    什么是Babel Babel 官方文档: https://babeljs.io/ Babel 中文文档:https://www.babeljs.cn/ 我们知道各个浏览器对JavaScript版本的支 ...

  2. 01、Git安装教程(windows)

    首先如下图:(点击next) 第二步:文件位置存储,可根据自己盘的情况安装 第三步:安装配置文件,自己需要的都选上,下一步 第四步:不创建启动文件夹,下一步: 第五步:选择默认的编辑器,我们直接用推荐 ...

  3. 【算法】蓝桥杯 试题 基础练习 Huffuman树

    资源限制 时间限制:1.0s   内存限制:512.0MB 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, ...

  4. (Hourglass)Windows倒计时软件 v1.9 电脑版

    (Hourglass)Windows倒计时软件是一款电脑系统小工具,能帮助大家快速进行最新的电脑系统倒计时设计,你可以设置自己的关机时间,帮助大家更好的管理自己的电脑应用. 链接:https://pa ...

  5. 【新人赛】阿里云恶意程序检测 -- 实践记录 11.24 - word2vec模型 + xgboost

    使用word2vec训练词向量 使用word2vec无监督学习训练词向量,输入的是训练数据和测试数据,输出的是每个词的词向量,总共三百个词左右. 求和:然后再将每行数据中的每个词的词向量加和,得到每行 ...

  6. 论文阅读笔记(十四)【AAAI2020】:Appearance and Motion Enhancement for Video-based Person Re-identification

    Introduction 本文的贡献:提出了基于视频的行人重识别模型:Appearance and Motion Enhancement Model(AMEM).该模型对两类信息进行提取:提出了App ...

  7. 【学习笔记】:一天搞定HTML

    PS:许多控制样式的标签在HTML5中都不推荐使用,建议使用CSS,如align,border等. 一.概念 HTML的英文全称:Hypertext Marked Language 超文本标记语言. ...

  8. JavaScript-跨浏览器事件处理程序(EventUtil)

    事件操作对象: var EventUtil= { //添加事件 addHandler: function (element, type, handler) { if (element.addEvent ...

  9. 【spring boot】SpringBoot初学(7)– 多数据源及其事务

    前言 github: https://github.com/vergilyn/SpringBootDemo 代码位置: 参考: Spring Boot Reference Guide , §77.2 ...

  10. Windows资源管理器卡死(未响应)的解决办法

    前几天笔记本出现一个莫名其妙的问题,不胜其扰,具体表现如下: A.打开资源管理器(我的电脑)时,会出现“正在处理它”的Loading提示,且地址栏会出现绿色进度条,进度条一般会持续几分钟(不影响进入分 ...