传送门

注意到矩形往上是无限的,考虑把点按 $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. log4j 多进程配置要注意的

    多进程写日志文件 方法一: 解决log4j公用配置文件,多进程同时写同一个log文件,因存在操作系统pv操作问题, 导致部分日志丢失.解决方案是不同的进程写不同的log文件 测试于:Log4j 1.2 ...

  2. triplet

    询问次数<=min(2*n,n+35) 一种类似hash的交互题 部分分n=5,限制10次 发现都问出来可以通过次数和大小确定所有的值和对应位置! n比较大 发现(X1,X2,i)能确定一些情况 ...

  3. HearthBuddy的狂野和休闲模式来回切换

    表现1 配置是标准,休闲模式 然后一直重复提示 select desire deck select causal mode 表现2 配置是狂野,休闲模式 然后一直提示 切换到狂野 切换到标准 把模式切 ...

  4. ccf 201512-3 画图(90)

    ccf 201512-3 画图(90) #include<iostream> #include<cstring> #include<algorithm> using ...

  5. C# 中使用RegisterShellHookWindow Hook窗体创建

    前言:最近在写一个桌面程序时需要全局HOOK 窗体的创建,但是在.net中SetWindowsHookEx()只可实现键盘鼠标的全局钩子,其余的全局钩子都需要使用DLL.难道就没有解决办法了么?经过长 ...

  6. jxbrowser java代码直接调用js代码

    https://blog.csdn.net/shuaizai88/article/details/73743669 final Browser browser = new Browser(); Bro ...

  7. Class 源码解读

    Class 获取包信息 /** * 获取此对象所在的包 * @revised 9 * @spec JPMS */ public Package getPackage() { // 原始类型和数组无 P ...

  8. Springboot获取resource的路径

    1.获取resource目录下的template路径 String path = Thread.currentThread().getContextClassLoader().getResource( ...

  9. 【经验】PHP开发中 &#65279 导致页头一行空白

    PHHP开发中  有的时候遇到页面顶部多出一行空白,审查元素发现头部有一行  比如在$this->dispay();方法中最前面加入ob_clean();   ================ ...

  10. ButterKnifer使用

    ButterKnifer使用 1.集成 github地址: https://github.com/JakeWharton/butterknife 1.1在主Moduel中的使用 在主moduel中的b ...