传送门

time limit per test  3 seconds
memory limit per test  256 megabytes
input  standard input
output  standard output

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.

--------------------------------------------------------------------------------------

Solution

不难看出,

两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离<==> x1=x2或y1=y2

对于所有x与y坐标,统计在对应竖直线与水平线上的点的个数,再删除重合点造成的重复计数即可,当然也要统计重合点的数目。

Implementation

#include <bits/stdc++.h>
using namespace std; typedef long long LL; map<pair<int,int>,LL> m;
map<int,LL> cnt[]; int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=; i<n; i++){
int x, y;
cin>>x>>y;
cnt[][x]++; cnt[][y]++;
m[{x,y}]++;
}
LL ans=;
for(int i=; i<; i++)
for(auto it=cnt[i].begin(); it!=cnt[i].end(); it++){
ans+=it->second*(it->second-)/;
}
for(auto it=m.begin(); it!=m.end(); it++)
ans-=it->second*(it->second-)/;
cout<<ans<<'\n';
return ;
}

用range-for还可将for-head写得更简洁些:

#include <bits/stdc++.h>
using namespace std; typedef long long LL; map<pair<int,int>,LL> m;
map<int,LL> cnt[]; int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=; i<n; i++){
int x, y;
cin>>x>>y;
cnt[][x]++; cnt[][y]++;
m[{x,y}]++;
}
LL ans=;
for(int i=; i<; i++)
for(auto it:cnt[i])
ans+=it.second*(it.second-)/;
for(auto it:m)
ans-=it.second*(it.second-)/;
cout<<ans<<'\n';
return ;
}

---------------------------------------------------

记录这道题是为了复习STL containers

基础不牢,地动山摇。

Codeforces 650A Watchmen的更多相关文章

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

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

  2. codeforces Codeforces 650A Watchmen

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

  3. Watchmen CodeForces - 650A

    Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Da ...

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

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

  5. A. Watchmen(Codeforces 650A)

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

  6. CodeForces 651C Watchmen map

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

  7. codeforces 651C Watchmen

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

  8. codefroces 650A. Watchmen

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

  9. CodeForces - 651C Watchmen (去重)

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

随机推荐

  1. 转: 使用virtualenv搭建独立的Python环境

    转自:  http://qicheng0211.blog.51cto.com/3958621/1561685 谢谢作者的辛苦付出 virtualenv可以搭建虚拟且独立的python环境,可以使每个项 ...

  2. kvm虚拟机日常管理和配置操作命令梳理

    KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理.1)查看KVM虚拟机配置文件及运行状态KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/autostart目录是配置kvm ...

  3. WPF数据绑定Binding(二)

    WPF数据绑定Binding(二) 1.UI控件直接的数据绑定 UI对象间的绑定,也是最基本的形式,通常是将源对象Source的某个属性值绑定 (拷贝) 到目标对象Destination的某个属性上. ...

  4. MySql表大小、行大小和列大小的限制

    参见官网文档: http://dev.mysql.com/doc/refman/5.7/en/table-size-limit.htmlhttp://dev.mysql.com/doc/refman/ ...

  5. with(nolock)的用法

    with(nolock)的介绍 大家在写查询时,为了性能,往往会在表后面加一个nolock,或者是with(nolock),其目的就是查询是不锁定表,从而达到提高查询速度的目的. 当同一时间有多个用户 ...

  6. 如何使用Native Messaging API 打开window程序

    问 如何使用Native Messaging API 打开window程序 cmd javascript terminal chrome Tychio 2013年03月26日提问 关注 1 关注 收藏 ...

  7. matlab矩阵合并及相关运算

    1.matlab允许向量(和矩阵)合并,且matlab提供了两种合并方式,[a,b]和[a;b],两者的结果是不一样的. a=rand(2,3): b=rand(2,3): c=[a;b]: d=[a ...

  8. 信息安全系统设计基础exp_3

    详情请看搭档20135322郑伟博客,传送门如下:http://www.cnblogs.com/zhengwei0712/p/4996017.html

  9. 八款Android 开发者必备的小工具

    Photo from https://www.airpair.com 在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大 ...

  10. grootJs 属性过滤器

    index10.html <html><head> <title>属性过滤器</title> <script src="jquery-1 ...