C. Watchmen
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.

题意: n个点  分别给出x,y坐标

两种两点的计算方式  |xi - xj| + |yi - yj|.       .

问 有多少种点的组合使得 两种两点的计算方式的结果相等      欧几里得距离等于曼哈顿距离

题解: 等式两边平方 整理移项之后可以发现  两点的x坐标相等或者y坐标相等情况下两种计算方式结果相等

用了 multiset+pair

其中最关键的处理是 当x y都对应相等情况下 去重处理

用的是pair

x相等的+y相等的-xy相等的

 #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll __int64
using namespace std;
int n;
multiset<int>s1;
multiset<int>s2;
pair<int,int>gg;
multiset<pair<int,int > >ggg;
int a[],b[];
ll jishu=;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d %d",&a[i],&b[i]);
gg.first=a[i];
gg.second=b[i];
ggg.insert(gg);
s1.insert(a[i]);
s2.insert(b[i]);
}
for(int i=;i<=n;i++)
{
ll exm=s1.count (a[i]);
jishu=jishu+exm*(exm-)/;
s1.erase(a[i]);
}
for(int i=;i<=n;i++)
{
ll exm=s2.count(b[i]);
jishu=jishu+exm*(exm-)/;
s2.erase(b[i]);
}
//printf("%I64d\n",jishu);
for(int i=;i<=n;i++)
{
gg.first=a[i];
gg.second=b[i];
ll exm=ggg.count(gg);
jishu=jishu-exm*(exm-)/;
ggg.erase(gg);
}
printf("%I64d\n",jishu);
return ;
}

Codeforces Round #345 (Div. 2) C (multiset+pair )的更多相关文章

  1. Codeforces Round #249 (Div. 2)B(贪心法)

    B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #250 (Div. 2)A(英语学习)

    链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...

  3. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  4. Codeforces Round #272 (Div. 1)D(字符串DP)

    D. Dreamoon and Binary time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  5. Codeforces Round #554 (Div. 2)-C(gcd应用)

    题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k ...

  6. Codeforces Round #532 (Div. 2)- C(公式计算)

    NN is an experienced internet user and that means he spends a lot of time on the social media. Once ...

  7. Codeforces Round #527 (Div. 3)F(DFS,DP)

    #include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N] ...

  8. Codeforces Round #618 (Div. 1)A(观察规律)

    实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...

  9. Codeforces Round #272 (Div. 1)C(字符串DP)

    C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. TW实习日记:第27天

    今天依旧是磨洋工的一天,说真的,被存在各种问题的后端接口把耐心和动力都给磨没了.于是一天就又在沟通接口问题中度过了,完善了一个新功能,将一个新功能开发到了一半.效率可真是够低的,唉.然后不知道为什么突 ...

  2. lintcode671 循环单词

    循环单词   The words are same rotate words if rotate the word to the right by loop, and get another. Cou ...

  3. lintcode373 奇偶分割数组

    奇偶分割数组 分割一个整数数组,使得奇数在前偶数在后. 您在真实的面试中是否遇到过这个题? Yes 样例 给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]. 我的方法:设定两个数组,分别 ...

  4. RNN概述-深度学习 -神经网络

    一 RNN概述    前面我们叙述了BP算法, CNN算法, 那么为什么还会有RNN呢?? 什么是RNN, 它到底有什么不同之处? RNN的主要应用领域有哪些呢?这些都是要讨论的问题. 1) BP算法 ...

  5. Jquery复选框

    Jquery复选框 1.checkbox list选择 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  6. javaIO--文件操作类

    文件操作类主要是使用File类的各种方法对文件和目录进行操作.包括文件名.文件长度.最后修改时间和是否只读等,提供获得当前文件的路径名.判断文件是否存在.创建.删除文件和目录等一系列的操作方法. 下面 ...

  7. 【Docker 命令】 - search 命令

    docker search : 从Docker Hub查找镜像 语法 docker search [OPTIONS] TERM OPTIONS说明: --automated :只列出 automate ...

  8. centos7编译安装redis遇坑

    编译redis时:make cc Command not found 原因分析:没有安装gcc,执行: yum install gcc 编译redis时:error: jemalloc/jemallo ...

  9. Delphi 模式窗体返回值ModalResult的使用方法及注意事项

    1.基础知识简介: ModalResult是指一个模式窗体(form.showmodal)的返回值,一般用于相应窗体上按钮的ModalResult属性: 显示完窗体(关闭)后,会返回此属性预设的值做为 ...

  10. 【.Net】C#文本文件(.txt)读写

    目录 前言 读取txt文件 写入txt文件 前言 计算机在最初只支持ASCII编码,但是后来为了支持其他语言中的字符(比如汉字)以及一些特殊字符(比如€),就引入了Unicode字符集.基于Unico ...