传送门

注意到矩形往上是无限的,考虑把点按 $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. ZooKeeper的简述

    一.简介 ZooKeeper是一个高性能,分布式的,开源分布式应用协调服务.它提供了简单原始的功能,分布式应用可以基于它实现更高级的服务,比如同步,集群管理,命名空间,配置维护等.ZooKeeper使 ...

  2. LeetCode 23. 合并K个排序链表(Merge k Sorted Lists)

    题目描述 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [   1->4->5,   1->3->4,   2->6 ] 输出: ...

  3. pure-ftpd搭建简单的Ubuntu FTP服务器

    Linux下的ftpd很多,Ubuntu下常用vsftpd, proftpd和pure-ftpd,当初使用的就是proftpd. 不过前两者有个致命的问题就是内码转换,它们默认使用UTF-8编码,而W ...

  4. leetcode324 摆动排序II

      1. 首先考虑排序后交替插入 首尾交替插入,这种方法对于有重复数字的数组不可行: class Solution { public: void wiggleSort(vector<int> ...

  5. System 源码阅读

    System 属性说明 /** * System 类包含了几个有用的字段和方法,并且不能被实例化. * * @author unascribed * @since 1.0 */ public fina ...

  6. openerp学习笔记 对象调用(创建、修改),用于后台代码创建和更新对象

    #服务卡创建,自动更新服务卡为开卡状态    def create(self, cr, uid, values, context=None):        values['state'] = '1' ...

  7. 【VBA】学习中出现的错误

    1.自定义函数 自定义函数尽量不要使用,容易导致excel卡,让你怀疑人生!!!

  8. tensorflow读取图片案例

    1.知识点 """ 1.图片读取流程与API: 1.构造图片文件队列 文件队列API: a)tf.train.string_input_producer(string_t ...

  9. Springboot2.0实现URL拦截

    1.创建一个登陆拦截器SecurityInterceptor,它继承HandlerInterceptorAdapter类 package com.cn.commodity.config; import ...

  10. SAS数据挖掘实战篇【三】

    SAS数据挖掘实战篇[三] 从数据挖掘概念到SAS EM模块和大概的流程介绍完之后,下面的规划是[SAS关联规则案例][SAS聚类][SAS预测]三个案例的具体操作步骤,[SAS的可视化技术]和[SA ...