传送门

注意到矩形往上是无限的,考虑把点按 $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. Centos 7.6 安装Mysql5.7(离线)

    Centos 7.6 安装Mysql5.7(离线) 标签(空格分隔): mysql 安装包下载 https://dev.mysql.com/downloads/mysql/ [image.png-14 ...

  2. phpcms9 从注入点入手和 从前台getshell

    弄了3天了  这个点 总结一下这三天的坑吧 0X01 注入点入手 /index.php?m=wap&c=index&a=init&siteid=1 获取cookie 传给 us ...

  3. Spring boot 读取resource目录下的文件

    背景:最近做项目重构将以前的ssh + angular js架构,重构为spring boot + vue.项目是一个数据管理平台,后台涉及到多表关联查询,数据导入导出等. 问题:读取resource ...

  4. win10专业版安装docker实战

    在win10专业版上安装docker 一,下载Docker for Windows Installer.exe 二,在程序面板---程序----程序和功能中找到启动或关闭windows功能,将hype ...

  5. [转]java常量池理解总结

    一.相关概念 什么是常量用final修饰的成员变量表示常量,值一旦给定就无法改变!final修饰的变量有三种:静态变量.实例变量和局部变量,分别表示三种类型的常量. Class文件中的常量池在Clas ...

  6. 学习笔记01:《开放平台产品成长之路-POP》

    当看到一些比较好的书籍和视频内容时,希望自己可以总价归纳下来,一方面是好的东西希望可以分享给大家,另一方面希望自己能很好的吸收并转化成掌握的知识,所以有了这个系列的学习笔记,共勉,今天的你比昨天更博学 ...

  7. git push 本地项目推送到远程分支[z]

    大家有的时候,会在本地新建项目,这里说一下在本地项目建立本地git仓库,然后push到远程仓库的步骤 1.在本地项目的文件夹下,git仓库初始化 git init 初始化本地git仓库 2. git ...

  8. python常见报错

    1.Pycharm No module named requests 的解决方法 pip install requests 然后重启pycharm

  9. 配置 Nginx 错误页面优雅显示

    [root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf ...... http { location / { root html/www; i ...

  10. C# 函数返回多个值的方法

    有时候我们需要一个函数返回多个值,网上更多是用out实现,我个人很喜欢用tuple方法. tuple是一个元组,最多支持7个元素,再多需要嵌套等方法实现. 使用元组定义函数的方法如下: public ...