A. Watchmen

当欧几里得距离和曼哈顿距离相等时,\(x1==x2||y1==y2\)

这两个条件满足其一。这和容斥原理一样,至少选择一个的条件。

我们可以计算xi,以及小于i之前的这些,这样可以保证只计算一次。

然后容斥一下计算答案。

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back using namespace std; void solve()
{
int n;cin>>n;
map<int,int>cntx,cnty;
map<pii,int>s;
int ans=0,k=0;
rep(i,1,n){
int x,y;cin>>x>>y;
ans+=cntx[x]+cnty[y]-s[{x,y}];
cntx[x]++;
cnty[y]++;
s[{x,y}]++;
}
cout<<ans<<endl;
} signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
// cin>>_;
// while(_--)
solve();
return 0;
}

Codeforces Round 345 (Div. 1)A. 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 Round #345 (Div. 1) A. Watchmen 模拟加点

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

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

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

  4. Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)

    题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

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

  7. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  8. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  9. Codeforces Round #345 (Div. 2) C (multiset+pair )

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

  10. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

随机推荐

  1. gpedit.msc 打不开

    win10系统推出已有不短的时间了,朋友们也纷纷升级了win10系统,但是暴露的问题也是越来越多,比如win10系统打开运行输入gpedit.msc命令时却提示找不到文件.那出现win10打不开gpe ...

  2. C# 理解委托与事件(烧水壶例子)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  3. C/C++ Zlib实现文件压缩与解压

    在软件开发和数据处理中,对数据进行高效的压缩和解压缩是一项重要的任务.这不仅有助于减小数据在网络传输和存储中的占用空间,还能提高系统的性能和响应速度.本文将介绍如何使用 zlib 库进行数据的压缩和解 ...

  4. Libevent [补档-2023-08-29]

    libevent的使用 8-1 安装 ​ 自己百度一下,安装它不是特别难,加油!!! 8-2 libevent介绍 ​ 它是一个开源库,用于处理网络和定时器等等事件.它提供了跨平台的API,能够在不同 ...

  5. Linux提取日志中的IP地址并去重

    原日志文件:logger.log  内容: {"peer":"kts_001","type":"http"," ...

  6. Redis有哪些潜在的慢操作?

    Redis作为内存数据库,访问速度快是最大的特点,那么,什么情况下,Redis也会变慢呢? Redis底层数据结构 Redis有5种基本数据类型:String,List,Hash,Set,ZSet 有 ...

  7. gcc-11/g++-11安装

    终端依次输入 sudo add-apt-repository ppa:ubuntu-toolchain-r/test #添加工具链存储库 sudo apt-get install gcc-11 #安装 ...

  8. 【译】介绍 MSTest Runner – CLI、Visual Studio 等

    原文 | Amaury Levé, Marco Rossignoli, Jakub Jareš 翻译 | 郑子铭 我们很高兴推出 MSTest runner,这是一个用于 MSTest 测试的新型轻量 ...

  9. js 获取css非行内样式,你应该了解的getComputedStyle方法

     壹 ❀ 引 我们知道书写css有三种做法,它们分别是行内样式,内嵌样式和外部引用.我们来看个例子,下面这个div分别通过内部样式添加了颜色,内嵌样式添加了字体大小,外部引入样式添加了宽度. < ...

  10. NC20325 [SDOI2009]HH的项链

    题目链接 题目 题目描述 HH有一串由各种漂亮的贝壳组成的项链. HH相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一 段贝壳,思考它们所表达的含义. HH不断地收集新的贝壳,因此他的项链 ...