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 ...
随机推荐
- 本月周六周日LIST集合
最近项目中有用到本月所有的周六,周日,特此分享一下! 算法思路:写一个循环,条件为本月开始日期.本月截至日期,通过循环获取第一个周六,加一天就是周日,每增加六天就是下一个周六,依次类推,循环到月末 代 ...
- Java8-Concurrency
import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public class Concurrency1 { pu ...
- 05_centos7安装python3
https://www.cnblogs.com/FZfangzheng/p/7588944.html https://www.cnblogs.com/simuhunluo/p/7704765.html ...
- 多线程爬取猫眼电影TOP100并保存到mongo数据库中
import requests import re import json from requests.exceptions import RequestException from multipro ...
- Shiro (包含权限满足其中一个就通过的用法)
方法/步骤 1 web.xml添加配置 <!-- shiro过滤器 --> <filter> <filter-name>shiroFilter</filter ...
- trie上构建后缀数组
例题: 往事太多,有时候忘了就忘了吧. 如果有非记不可的,就只能用点附加手段啦! 我们定义一棵往事树是一个 n 个点 n-1 条边的有向无环图,点编号为 1到 n,其中 1 号点被称为是根结点,除根结 ...
- box-orient
box-orient 语法: box-orient:horizontal | vertical | inline-axis | block-axis 默认值:horizontal 适用于:伸缩盒容器大 ...
- mysql常用的索引种类
一.索引 MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度 二.索引类型 Mysql目前主要有以下几种索引类型:FULLTEXT,HASH,BTREE,RT ...
- easyui-textbox输入框数字校验
输入框数字校验 $("#reg_num").textbox('textbox').bind('keyup', function(e){ $("#reg_num" ...
- Hadoop环境搭建|第一篇:linux操作系统安装
一.安装工具及文件 优盘:8G(非kingston优盘) 制作启动盘工具:Universal_USB_Installer 操作系统:CentOs操作系统 二.注意事项 安装过程的详细步骤,这里就不再赘 ...