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 ...
随机推荐
- python 传参
python不允许程序员选择采用传值还是传引用.Python参数传递采用的肯定是“传对象引用”的方式.这种方式相当于传值和传引用的一种综合.如果函数收到的是一个可变对象(比如字典或者列表)的引用,就能 ...
- .net core 版本支持
NetCore sdk并不是每个版本都支持VS2017工具,也不是每个版本的sdk版本号和Runtime版本号都一样,这就需要我们在创建某个版本的net core应用时注意:使用不同版本的vs时需要对 ...
- c语言学习、工作相关必备的常用网站
1.https://zh.cppreference.com/,c.c++参考手册, 2.http://www.cplusplus.com/,在线查看c.c++函数的定义及用法 3.http://c-f ...
- C# MVC中直接执行Js
.NET MVC里如何在服务器端执行JS: 三种解决方案: 1.直接返回JavaScript. public ActionResult XXXAction1() { return JavaS ...
- Docker:18.x版本安装与卸载
Docker CE 分为 stable, test, 和 nightly 三个更新频道.每六个月发布一个 stable 版本 初始化机器 #1.关闭警报 vi /etc/inputrc #然后将set ...
- stl常数测试
如图: 数组的常数约为9.
- python编写弹球游戏的实现代码
#coding:utf- from tkinter import * import random import time class Ball: #创建一个球类 def __init__(self, ...
- Ubuntu14.04 挂载u盘
插入u盘后, $cat /proc/partitions 发现多了 sdb sdb4 sdb是统称,所以新插入的U盘就是/dev/sdb4 $ls /dev |grep sdb sdb sdb4 查看 ...
- c++ 数组赋值
// generate_n example #include <iostream> // cout #include <algorithm> // generate_n usi ...
- win10 下载安装tasm
下载tasm http://www.technorange.com/wp-content/uploads/Tasm%201.4%20Windows%207-Windows%208%2064%20bit ...