思路:

线段树 + 扫描线。

实现:

 #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. 自己实现sizeof+大小端测试

    #define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 同时大小端测试 如下 #include <stdio.h&g ...

  2. android studio连接MYSQL8.0报错:java.long.unsupportedOperation处理方案

    纠结了我大概一个星期了! 下载的别人的demo测试,因为还没学线程连接网络啥的 对方使用的版本是MYSQL5.1.14,我使用的8.0.18,同样都是阿里云服务器自建数据库. 由于是版本8.0,所以在 ...

  3. ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...

  4. BZOJ 3931 / Luogu P3171 [CQOI2015]网络吞吐量 (最大流板题)

    题面 中文题目,不解释: BZOJ传送门 Luogu传送门 分析 这题建图是显然的,拆点后iii和i′i'i′连容量为吞吐量的边,根据题目要求,111和nnn的吞吐量看作∞\infty∞. 然后用di ...

  5. OI 常用模板 手写

    线性筛素数 (例题 洛谷P3383) bool p[50000010]; int cnt = 0; int prime[10000010]; inline void init() { int N = ...

  6. 畅通工程续(HDU 1874)(简单最短路)

    某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰. 现在 ...

  7. scrapy框架之spider

    爬取流程 Spider类定义如何爬取指定的一个或多个网站,包括是否要跟进网页里的链接和如何提取网页内容中的数据. 爬取的过程是类似以下步骤的循环: 1.通过指定的初始URL初始化Request,并指定 ...

  8. c++ 数组赋值

    // generate_n example #include <iostream> // cout #include <algorithm> // generate_n usi ...

  9. 验证码的实现类ValidateCode

    package com.yujie.util; import javax.imageio.ImageIO;import java.awt.*;import java.awt.image.Buffere ...

  10. Qt 线程基础(QThread、QtConcurrent等) 2

    使用线程 基本上有种使用线程的场合: 通过利用处理器的多个核使处理速度更快. 为保持GUI线程或其他高实时性线程的响应,将耗时的操作或阻塞的调用移到其他线程. 何时使用其他技术替代线程 开发人员使用线 ...