CF1190D Tokitsukaze and Strange Rectangle
思路:
线段树 + 扫描线。
实现:
#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的更多相关文章
- Tokitsukaze and Strange Rectangle CodeForces - 1191F (树状数组,计数)
大意: 给定$n$个平面点, 定义集合$S(l,r,a)$表示横坐标$[l,r]$纵坐标$[a,\infty]$内的所有点. 求可以得到多少种不同的集合. 从上往下枚举底层最右侧点, 树状数组统计贡献 ...
- Codeforces 1190D. Tokitsukaze and Strange Rectangle
传送门 注意到矩形往上是无限的,考虑把点按 $y$ 从大到小考虑 对于枚举到高度为 $h$ 的点,设当前高度大于等于 $h$ 的点的所有点的不同的 $x$ 坐标数量为 $cnt$ 那么对于这一层高度 ...
- Codeforces - 1191F - Tokitsukaze and Strange Rectangle - 组合数学 - 扫描线
https://codeforces.com/contest/1191/problem/F 看了一下题解的思路,感觉除了最后一段以外没什么启发. 首先离散化x加快速度,免得搞多一个log.其实y不需要 ...
- Codeforces Round #573 (Div. 1)
Preface 军训终于结束了回来补一补之前的坑发现很多题目题意都忘记了 这场感觉难度适中,F由于智力不够所以弃了,E的话石乐志看了官方英文题解才发现自己已经胡了一大半就差实现了233 水平下降严重. ...
- Magolor的数据结构作业
\(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~ ...
- Codeforces Roundd #573 (Div. 2)
D. Tokitsukaze, CSL and Stone Game 题意:有n堆石头,每人每次只能去一颗石子,若轮到当前人没任何一堆石子可以取或当前人取到后剩下有俩堆石子个数相同则当前人输: 给定石 ...
- Codeforces Round #789 (Div. 2)
题集链接 A. Tokitsukaze and All Zero Sequence 题意 Tokitsukaze 有一个长度为 n 的序列 a. 对于每个操作,她选择两个数字 ai 和 aj (i≠j ...
- [LeetCode] Perfect Rectangle 完美矩形
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...
- [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 ...
随机推荐
- C#分隔字符串时遭遇空值
在C#中分隔字符串时,按特定字符进行分隔的时候可能会遇到空值,如何我现在传入的是Id的字符串,如:"1501,1502,1503,,1505",以逗号分隔,由于各种原因,导致传入的 ...
- 网络_05 STP HSRP
一.案例1:STP的基本配置 将S1配置成vlan1的主根,将S2配置成vlan2的次根 查看生成树的配置:show spanning-tree 查看某个vlan生成树的详细信息:show spann ...
- Apache 下载+安装
1.官网下载Apache 官网地址:https://httpd.apache.org/ 点击Download 上面那段话,大致意思:很高兴Apache服务器2.4.18版本的发布.在2.4.x的分支的 ...
- 【csp模拟赛6】计数--单调栈
对于60%的数据:暴力枚举对于100%的数据:因为排列是随机的,所以从每个点向后可能的差值最多2logn个,所以答案最多只可能有nlogn种,用单调队列找出来统计即可 维护对于每个位置,向右能影响到的 ...
- 2019CCPC-江西省赛C题 HDU6569 GCD预处理+二分
Trap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- Luogu4191 [CTSC2010]性能优化【多项式,循环卷积】
题目描述:设$A,B$为$n-1$次多项式,求$A*B^C$在系数模$n+1$,长度为$n$的循环卷积. 数据范围:$n\leq 5*10^5,C\leq 10^9$,且$n$的质因子不超过7,$n+ ...
- C语言学习笔记4-数据输入和输出
本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/50752127 作者:jadeshu 邮箱: jades ...
- Java 生成六位短信验证码
在<Java 生成三位随机数>中,简要介绍了使用Java生成三位随机数的方法,前几天在工作中遇到生成6位短信验证码的需求,验证码由6位随机数字构成,不包含字母.6位随机数通常用作短信验证码 ...
- 【C/C++】Linux的gcc和g++的区别
Windows中我们常用vs来编译编写好的C和C++代码:vs把编辑器,编译器和调试器等工具都集成在这一款工具中,在Linux下我们能用什么工具来编译所编写好的代码呢,其实Linux下这样的工具有很多 ...
- flask中用类的方式构造视图函数
from flask import Flask from flask.views import MethodView app = Flask(__name__) class IndexView(Met ...