传送门

注意到矩形往上是无限的,考虑把点按 $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. 「CSA Round #41」BFS-DFS

    题目链接 戳我 \(Description\) 给出一个图的\(bfs\)序和\(dfs\)序,构造出一个满足条件的图,边的扫描顺序为读入顺序 \(Solution\) 这个题还是很简单的. 先来看看 ...

  2. Eclipse项目迁移到MyEclipse后,继承HttpServlet报错问题

    网上好多说法,比如要去对比eclipse和myeclipse的.project文件等等,但我的问题就是Libraries没有导入tomcat,导入之后,报错就消失了. 这里没有给出导入方法,只是给遇到 ...

  3. PHP ob_get_level嵌套输出缓冲

    PHP的输出缓存是可以嵌套的.用ob_get_level()就可以输出嵌套级别. 测试发现在cli和浏览器下输出结果不一样(PHP5.4). ob_level1.png手册说明如下: ob_get_l ...

  4. php post请求

    public function file_get_contents_post($url, $post){ $options = array( 'http'=> array( 'method'=& ...

  5. [Tool]截屏利器FSCapture7.6下载

    下载地址:https://pan.baidu.com/s/1XQ1P5hHwZd0NE7bdz_znQQ 或是:https://files.cnblogs.com/files/xiandedanten ...

  6. pid稳态控制

    https://blog.csdn.net/qq_25352981/article/details/81007075

  7. How to run a VBA macro when new mail is received in Outlook

    It can be very useful to run a VBA macro when new mail is received in Outlook. A customer asked me t ...

  8. Mongdb、Mysql、Redis、Memcache场景

    个人的一点理解,不确定一定准确,有不对处欢迎指出 全部数据使用mysql存储,确保安全.准确和持久 大数据.非安全性数据使用Mongodb 小数据.结构丰富.持久化(主从数据)使用redis 小数据. ...

  9. Eclipse使用高版本的jdk编译低版本的class文件的方法

    如题,在这两天使用eclipse工具编译代码时,编译出来的class文件拿UE工具查看,版本为1.8版本的,而本地使用的tomcat版本是1.6的,运行中报错Unsupported major.min ...

  10. Hibernate对象的状态分类

    对象的状态: 临时状态Transient: 与数据库没有对应,跟Session没有关联 一般是新new出的对象 持久化状态Persistent: 对象在Session的管理之中,最终会有对应的数据库记 ...