题目链接:https://vjudge.net/contest/237394#problem/C

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,代表有n个点,下面n行代表每个点的坐标,求用以上两种方式求出答案一样的点有多少个

个人思路:第一想法是直接暴力,(这时候还不太清楚怎么大概判断是否会超时),然后很正常的超时了,这里介绍一下怎么大概估计一下是否会超时

1000ms大概能判断10^7的数据,而且是在数据比较水,条件比较好的情况下,反正在这时候就已经很极限了,可能有时候能判断10^8的数据,这就要求后台数据特别水,而且编译环境好的情况下才有可能ac,而这题时限是3000ms,所以充其量估计也就能判3*10^8的数据,所以直接做肯定是超时的,那么下面看一下用

map来做,嗯。。。很快

还有,两个点要满足条件,必须要x相同或者y相同,但要记住减去重复的点

看代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=2e5+;
const ll maxa=;
const double x=(1.0+sqrt(5.0))/;
#define INF 0x3f3f3f3f3f3f
//n*(n-1)/2等价于0+1+2+···+n-1
map<ll,ll>mp1;//用于计算有多少个x相同的点
map<ll,ll>mp2;//用于计算有多少个y相同的点
map<pair<ll,ll>,ll>mp;//用于计算有多少个x和y都相同的点
int main()
{
mp1.clear();
mp2.clear();
mp.clear();//清空
int n;
ll a,b,ans=,num=;
cin>>n;
for(int i=;i<n;i++)
{
cin>>a>>b;
num+=mp[make_pair(a,b)];//发现map有个好处,就是关键字是什么都可以,这就大大方便了存储
mp[make_pair(a,b)]++;
ans+=mp1[a];
mp1[a]++;
ans+=mp2[b];
mp2[b]++;
}
cout<<ans-num<<endl;
return ;
}

C - Watchmen的更多相关文章

  1. 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 ...

  2. Codeforces 650A Watchmen

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

  3. CodeForces 651C Watchmen map

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

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

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

  5. codeforces 651C Watchmen

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

  6. CodeForces 651 C Watchmen

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

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

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

  8. codeforces 650 C. Watchmen(数学公式)

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

  9. Watchmen CodeForces - 650A

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

随机推荐

  1. CF1060B:Maximum Sum of Digits

    我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:http://codeforces.com/problemset/problem/ ...

  2. 【P2P网贷新手入门】详解借款标的种类及其风险

    不同于国外的网贷平台以信用借款标为主,在中国,我们投资网贷平台会看到多样借款标,而投资人往往弄不清自己投资的标属于什么类型的标,特点怎么样,风险如何. 抵 押 标 定义:借款人用自己的房屋车辆等实物在 ...

  3. Java常见设计模式之工厂模式

    工厂模式在我们日常的应用中应当算是比较广泛的一种设计模式了.今天让我们一起来学习一下,工厂的设计模式. 工厂模式在<Java与模式>中分为三类:     1)简单工厂模式(Simple F ...

  4. mysql的简单操作

    创建数据库并设定字符集: CREATE  DATABASE hidb CHARACTER SET ‘utf8’; 使用数据库: use hidb; 删除数据库: DROP DATABASE hidb; ...

  5. 十二:JAVA I/O

     输入模式                                                          输出模式 ⑴字节输入流:InputStream ⑵字节输出流:Output ...

  6. ss3

    1)执行如下命令,进行安装shadowsocks(命令需要一条条的输入,然后回车,执行完一条,在执行下一条命令),过程中可能会让你选择确认的地方,直接输入"y"回车即可: yum ...

  7. 问题:C#发布的项目浏览时出现“Server Application Unavailable”错误;结果:Server Application Unavailable出现的原因及解决方案小结

    Server Application Unavailable出现的原因及解决方案小结 作者: 字体:[增加 减小] 类型:转载 时间:2012-05-23 今天在服务器安装了个.net 4.0 fra ...

  8. win10系统-javac不是内部或外部命令

    给笔记本装了一个ssd,上午装的系统,重新搞jdk,设置JAVA_HOME之后,cmd运行javac报 “javac不是内部或外部命令”各种懵逼,试了好几次才发现Path路径里面不能用%JAVA_HO ...

  9. 代码 c++实现动态栈

    //============================================================================ // Name : 栈.cpp // Au ...

  10. Matlab零碎知识

    1.不定积分的求取 int syms x;%为自变量 f=x.^2; s=int(f,x); 其中显示辅助函数simple()和pretty()