思路:

线段树 + 扫描线。

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
int n, x[N], y[N], bit[N];
vector<int> v[N];
void compress(vector<int>& x)
{
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
}
int lowbit(int x) { return x & -x; }
void add(int i, int x)
{
while (i <= n) { bit[i] += x; i += lowbit(i); }
}
int sum(int i)
{
int ans = ;
while (i) { ans += bit[i]; i -= lowbit(i); }
return ans;
}
int main()
{
while (cin >> n)
{
memset(bit, , sizeof bit);
for (int i = ; i <= n; i++) v[i].clear();
vector<int> vx, vy;
for (int i = ; i <= n; i++)
{
cin >> x[i] >> y[i];
vx.push_back(x[i]); vy.push_back(y[i]);
}
compress(vx); compress(vy);
for (int i = ; i <= n; i++)
{
x[i] = lower_bound(vx.begin(), vx.end(), x[i]) - vx.begin() + ;
y[i] = lower_bound(vy.begin(), vy.end(), y[i]) - vy.begin() + ;
v[y[i]].push_back(x[i]);
}
ll ans = ;
for (int i = n; i >= ; i--)
{
sort(v[i].begin(), v[i].end());
for (int j = ; j < v[i].size(); j++)
{
int t = v[i][j];
if (sum(t) - sum(t - )) continue;
add(t, );
}
int prev = ;
for (int j = ; j < v[i].size(); j++)
{
int t = v[i][j];
ans += 1ll * (sum(t - ) - sum(prev) + ) * (sum(n) - sum(t) + );
prev = t;
}
}
cout << ans << endl;
}
return ;
}

CF1190D Tokitsukaze and Strange Rectangle的更多相关文章

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

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

  2. Codeforces 1190D. Tokitsukaze and Strange Rectangle

    传送门 注意到矩形往上是无限的,考虑把点按 $y$ 从大到小考虑 对于枚举到高度为 $h$ 的点,设当前高度大于等于 $h$ 的点的所有点的不同的 $x$ 坐标数量为 $cnt$ 那么对于这一层高度 ...

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

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

  4. Codeforces Round #573 (Div. 1)

    Preface 军训终于结束了回来补一补之前的坑发现很多题目题意都忘记了 这场感觉难度适中,F由于智力不够所以弃了,E的话石乐志看了官方英文题解才发现自己已经胡了一大半就差实现了233 水平下降严重. ...

  5. Magolor的数据结构作业

    \(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~ ...

  6. Codeforces Roundd #573 (Div. 2)

    D. Tokitsukaze, CSL and Stone Game 题意:有n堆石头,每人每次只能去一颗石子,若轮到当前人没任何一堆石子可以取或当前人取到后剩下有俩堆石子个数相同则当前人输: 给定石 ...

  7. Codeforces Round #789 (Div. 2)

    题集链接 A. Tokitsukaze and All Zero Sequence 题意 Tokitsukaze 有一个长度为 n 的序列 a. 对于每个操作,她选择两个数字 ai 和 aj (i≠j ...

  8. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  9. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

随机推荐

  1. 一个有趣的 SQL 查询

    来源:站长资讯 一个朋友有这样一个SQL查询需求: 有一个登录表(tmp_test),包含用户ID(uid)和登录时间(login_time).表结构如下: ********************* ...

  2. [Google Guava] 3-缓存

    原文地址  译文地址    译者:许巧辉  校对:沈义扬 范例 01 LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder() ...

  3. python修改linux主机ip

    修改虚拟机的主机ip 和hostname import os, sys def conf_ip(ip): iplist = [] f = open("/etc/sysconfig/netwo ...

  4. Activiti服务类- FormService服务类

    转自:https://www.cnblogs.com/liuqing576598117/p/9814953.html 1.获取//通过流程定义ID获取表单字段集合StartFormData start ...

  5. [Luogu] 【模板】点分治1

    // 模板题#include <bits/stdc++.h> ; , head[N], dis[N]; ]; int size[N], maxson[N], Root; bool vis[ ...

  6. codeforces 1272F dp+记录路径

    题意 给出两个括号序列 \(S\) 和 \(T\),让你构造一个最短的合法括号序列使 \(S\) 和 \(T\) 是它的子序列. 分析 设 \(dp[i][j][k]\) 为这个最短的合法括号序列的前 ...

  7. setjmp

    #include <setjmp.h> #include <stdio.h> jmp_buf j; void raise_exception(void) { printf(&q ...

  8. 编写第一个Servlet程序

    在开始这一节之前呢,我们还需要把Tomcat配置到Eclipse中,配置的方式很简单,打开Eclipse,Window,Preferences,进入到这个页面 将Tomcat的安装目录配置到Eclip ...

  9. oracle insert into 多条数据

    mysql : insert into tablename (column1,column2) values ('aa','bb'), ('dd','cc'), ('ee','ff'); oracle ...

  10. docker 容器内部访问宿主机

    在宿主机执行: ifconfig 然后查看 docker0 的那个网卡的 ip 地址,比如我的是 172.18.0.1