传送门

注意到矩形往上是无限的,考虑把点按 $y$ 从大到小考虑

对于枚举到高度为 $h$ 的点,设当前高度大于等于 $h$ 的点的所有点的不同的 $x$ 坐标数量为 $cnt$

那么对于这一层高度 $h$ 我们就有 $cnt(cnt+1)/2$ 种不同的 $l$,$r$ ,使得矩形内点集不同

发现对于某些 $x$ 在这一层相邻两点之间,高度大于 $h$ 的点,这样又重复算了它们的贡献,所有要再扣掉

直接用树状数组维护一下当前区间内不同的 $x$ 的数量即可

因为离散化了判断 $x$ 是否出现过显然直接开一个桶就行....

代码是真的挺简单的,也很容易看懂吧...

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=4e5+;
int n,b[N],m;
struct poi {
int x,y;
poi (int _x=,int _y=) { x=_x,y=_y; }
inline bool operator < (const poi &tmp) const {
return y!=tmp.y ? y>tmp.y : x<tmp.x;//按y从大到小,x从小到大排序
}
}p[N];
struct BIT {
int t[N];
inline void add(int x) { while(x<=m) t[x]++,x+=x&-x; }
inline int ask(int x) { int res=; while(x) res+=t[x],x-=x&-x; return res; }
}T;
ll Ans;
int tmp[N],tot;
bool vis[N];
int main()
{
n=m=read(); int x,y;
for(int i=;i<=n;i++)
{
x=read(),y=read();
p[i]=poi(x,y); b[i]=x;
}
sort(b+,b+m+); m=unique(b+,b+m+)-b-;
for(int i=;i<=n;i++) p[i].x=lower_bound(b+,b+m+,p[i].x)-b;//离散化
sort(p+,p+n+); int cnt=;
for(int i=;i<=n;i++)
{
int r=i; tmp[tot=]=;/*注意加入0*/ tmp[++tot]=p[i].x;
while(p[r+].y==p[i].y) tmp[++tot]=p[++r].x;
tmp[++tot]=m+;//注意加入m+1
tot=unique(tmp+,tmp+tot+)-tmp-;
for(int j=;j<tot;j++)
{
int L=tmp[j]+,R=tmp[j+]-;
int t=T.ask(R)-T.ask(L-);
Ans-=1ll*t*(t+)/;//扣掉会重复算的方案数
}
for(int j=i;j<=r;j++)
{
if(vis[p[j].x]) continue;
vis[p[j].x]=; T.add(p[j].x); cnt++;//不同就加入树状数组
}
Ans+=1ll*cnt*(cnt+)/; i=r;
}
printf("%lld\n",Ans);
return ;
}

Codeforces 1190D. Tokitsukaze and Strange Rectangle的更多相关文章

  1. Codeforces - 1191F - Tokitsukaze and Strange Rectangle - 组合数学 - 扫描线

    https://codeforces.com/contest/1191/problem/F 看了一下题解的思路,感觉除了最后一段以外没什么启发. 首先离散化x加快速度,免得搞多一个log.其实y不需要 ...

  2. Tokitsukaze and Strange Rectangle CodeForces - 1191F (树状数组,计数)

    大意: 给定$n$个平面点, 定义集合$S(l,r,a)$表示横坐标$[l,r]$纵坐标$[a,\infty]$内的所有点. 求可以得到多少种不同的集合. 从上往下枚举底层最右侧点, 树状数组统计贡献 ...

  3. CF1190D Tokitsukaze and Strange Rectangle

    思路: 线段树 + 扫描线. 实现: #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n ...

  4. Codeforces 718A Efim and Strange Grade 程序分析

    Codeforces 718A Efim and Strange Grade 程序分析 jerry的程序 using namespace std; typedef long long ll; stri ...

  5. [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)

    [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...

  6. codeforces 719C. Efim and Strange Grade

    C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. 【codeforces 128C】Games with Rectangle

    [题目链接]:http://codeforces.com/problemset/problem/128/C [题意] 让你一层一层地在n*m的网格上画k个递进关系的长方形;(要求一个矩形是包含在另外一 ...

  8. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)

    题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下 ...

  9. Codeforces 1190C. Tokitsukaze and Duel

    传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...

随机推荐

  1. JIRA绑定邮箱

    [管理-系统-外发邮件] 之前配置QQ邮箱没有成功,后来使用阿里邮箱一次就成功了 [保存]成功后可以测试一下

  2. 访问zabbix首页无法正常登陆

    访问: http://IP/zabbix/ (1) You should see the first screen of the frontend installation wizard. (2) 检 ...

  3. 修改hive 默认fs为s3 遇到的坑

    问题: hive我修改了 默认的f <property> <name>fs.defaultFS</name> <value>hdfs://...:802 ...

  4. 邻居子系统输出 之 neigh_output、neigh_hh_output

    概述 ip层在构造好ip头,检查完分片之后,会调用邻居子系统的输出函数neigh_output进行输出,输出分为有二层头缓存和没有两种情况,有缓存时调用neigh_hh_output进行快速输出,没有 ...

  5. 20165213 Exp6 信息搜集与漏洞扫描

    信息搜集与漏洞扫描 一. 实践内容 (1)各种搜索技巧的应用 利用Google Hacking Datebase搜索. 尝试搜索http相关的漏洞,可以看到漏洞的相关信息. 也可以使用过滤器进行过滤, ...

  6. tp5中很牛皮的一句sql语句,三个条件(两个不确定条件,一个硬性条件)

    $result = Db::table('xxxxxx')   // 表名 ->alias('g') ->join('xxxxx_2 u','g.user_id = u.id') -> ...

  7. ssh不输入密码

    要通过跳转机器远程其他的机器 不方便使用秘钥 每次都要输入密码也很烦 使用sshpass可以复制一行命令就直接登录了 我的跳板机是Centos7安装sshpass很简单 直接如下搞定 yum inst ...

  8. AttributeError:module 'keras.engine.topology' has no attribute 'load_weights_from_hdf5_group_by_name

    在jupyter notebooks上运行tensorflow-keras的Mask R-CNN时遇到如下错误: 参考博客中写了两种解决方案: 解决方案一:报错是由于keras版本不对造成的.load ...

  9. C#产生随机验证码的代码

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  10. Java之HSF搭建demo

    1.去阿里云官网下载Demo edas-app-demo.zip 2.下载Ali-Tomcat和Pandora,注意红色下面字体 a)下载 Ali-Tomcat,保存后解压至相应的目录(如:d:\wo ...