Description

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.

Sample Input

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

Hint

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.

思路:把题目的两个公式同时平方,化简得只要xi=xj或者yi=yj,等式就会成立,暴力的话容易超时,学长当时给了题解,

用stl的map去写,后来自己也看了下,的确很好用

统计x相等的个数加上y相等的个数减去xy同时相等的个数,就是结果了

代码是学长给的,发现比网上的一些简单多了

 #include <iostream>
#include <map>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
map<int,int> mx;
map<int,int> my;
map<pair<int,int>,int>mxy;
long long ans = ;
for (int i=;i<n;++i)
{
int x,y;
cin>>x>>y;
ans += mx[x]++;
ans += my[y]++;
ans -= mxy[make_pair(x,y)]++;
}
cout<<ans<<endl;
}
}

CodeForces 651C的更多相关文章

  1. codeforces 651C(map、去重)

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

  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

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

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

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

  5. Codeforces 651C Watchmen【模拟】

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

  6. CodeForces - 651C Watchmen (去重)

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

  7. Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. 后端springmvc,前端html5的FormData实现文件断点上传

    前言 最近项目中有使用到文件断点上传,得空便总结总结,顺便记录一下,毕竟“好记性不如烂笔头”. 后端代码: package com.test.controller; import java.io.Bu ...

  2. JAVA面试题基础部分(二)

    10.使用 final 关键字修饰一个变量时,是引用不能变,还是引用的对象不能变?使用 final 关键字修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内容还是可以改变的.例如,对于如下 ...

  3. [转]使用Fiddler进行iOS APP的HTTP/HTTPS抓包

    Fiddler不但能截获各种浏览器发出的HTTP请求, 也可以截获各种智能手机发出的HTTP/HTTPS请求.Fiddler能捕获iOS设备发出的请求,比如IPhone, IPad, MacBook. ...

  4. BZOJ 1146: [CTSC2008]网络管理Network 带修改主席树_树套树_DFS序

    Description M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个 部门之间协同工作,公司搭建了一个连接整个公司的通信网络.该网络的结构由N个路 ...

  5. 【转载】深入理解Java的接口和抽象类

    深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...

  6. 复习MySQL⑤查询、常用函数

    查询操作符列表 distinct操作符:用来消除重复记录. - 例: 查询fruits表中所有不重复的s_id select distinct s_id from fruits; 子查询:写在()中, ...

  7. Linux direct io使用例子

    Linux direct io使用 在linux 2.6内核上使用direct io不难,只需按照如下几点来做即可: 1,在open文件时加上O_DIRECT旗标,这样以通告内核我们想对该文件进行直接 ...

  8. top问题

    1. 从10万个数中找10个最大的数 对于这种题目,最普通的想法是先对这10万个数进行排序,然后再选取数组中前10个数,即为最后的答案,排序算法的时间复杂度不下于O(N lgN).最好的方法是建立一个 ...

  9. jQuery cxCalendar 日期选择器

    简介 cxCalendar 是基于 jQuery 的日期选择器插件. 它灵活自由,你可以自定义外观,日期的范围,返回的格式等. 版本: jQuery v1.7+ jQuery cxCalendar v ...

  10. 不用form怎么post数据

    数据传输是用户交互中最重要的环节,下面收集了几个数据传输的方法,作为记录(未测试,在使用之前需要测试,如果后面我测试了,会对已测试项进行标注) 一. 网址传递 <a href=”test.php ...