当前位置:网站首页>【集训DAY16】ALFA【凸壳】【计算几何】
【集训DAY16】ALFA【凸壳】【计算几何】
2022-07-29 23:52:00 【VL——MOESR】

思路:
先同时除以x,然后用凸壳维护,答案二分一下就行了
c o d e code code
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const long long MAXN = 5e5 + 10;
long long n, q, tota, totb;
pair<long long, long long> a[MAXN], b[MAXN], ca[MAXN], cb[MAXN];
long long cj(long long x, long long x1, long long y, long long y1) {
return (y - y1) * (x - x1);
}
void doa() {
sort(a + 1, a + 1 + n);
for(long long i = 1; i <= n; i ++) {
while(tota >= 1 && ca[tota].first == a[i].first
|| tota >= 2 && cj(a[i].first, ca[tota - 1].first, ca[tota - 1].second, ca[tota].second) >=
cj(ca[tota].first, ca[tota - 1].first, ca[tota - 1].second, a[i].second))
tota --;
ca[++ tota] = a[i];
}
}
void dob() {
sort(b + 1, b + 1 + n);
for(long long i = 1; i <= n; i ++) {
while(totb >= 1 && cb[totb].first == b[i].first
|| totb >= 2 && cj(b[i].first, cb[totb - 1].first, cb[totb - 1].second, cb[totb].second) >=
cj(cb[totb].first, cb[totb - 1].first, cb[totb - 1].second, b[i].second))
totb --;
cb[++ totb] = b[i];
}
}
int main() {
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
scanf("%lld%lld", &n, &q);
for(long long i = 1; i <= n; i ++) {
long long x, y;
scanf("%lld%lld", &x, &y);
a[i] = make_pair(x, y);
b[i] = make_pair(-x, -y);
}
doa();
dob();
while(q --) {
long long x;
scanf("%lld", &x);
if(x > 0) {
long long l = 1, r = tota;
while(l < r) {
long long mid = l + r >> 1;
if(ca[mid].first * x + ca[mid].second > ca[mid + 1].first * x + ca[mid + 1].second)
r = mid;
else l = mid + 1;
}
printf("%lld\n", ca[l].first * x * x + ca[l].second * x);
}
else if(x < 0) {
long long l = 1, r = totb;
while(l < r) {
long long mid = l + r >> 1;
if(cb[mid].first * x + cb[mid].second > cb[mid + 1].first * x + cb[mid + 1].second)
r = mid;
else l = mid + 1;
}
printf("%lld\n", - cb[l].first * x * x - cb[l].second * x);
}
else printf("0\n");
}
return 0;
}
边栏推荐
- 【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(下) -- 搜索历史
- Mysql8.0新特性之详细版本
- devops学习(七) sonarqube 代码质检工具
- 指令集数据产品如何设计和实现报表协同系统——基于指令集物联网操作系统的工业协同制造项目开发实践
- y81. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Monitoring Extension (12)
- C陷阱与缺陷 第3章 语义“陷阱” 3.10 为函数main提供返回值
- Getting Started with Sentinel
- C陷阱与缺陷 第5章 库函数 5.1 返回整数的getchar函数
- Elephant Swap: Provide arbitrage space in the crypto market with ePLATO
- Codeforces Round #805 (Div. 3)总结
猜你喜欢
随机推荐
经典论文-SqueezeNet论文及实践
Install PyCharm on Raspberry Pi
SQL Server、MySQL主从搭建,EF Core读写分离代码实现
YoloV5数据集自动划分训练集、验证集、测试集
Genesis与Axis Ventures互动密切
jenkins搭建部署详细步骤
HRNet-Facial-Landmark-Detection 训练自己数据集
决策树原理及代码实现
标签分发协议(LDP)
CesiumJS ^ source read [0] 2022 - article directory and source engineering structure
MySQL 用 BETWEEN AND 日期查询包含范围边界
Tkinter:功能按钮Button
Unity Addressables
很遗憾,没有一篇文章能讲清楚分布式事务
微信小程序获取手机号getPhoneNumber接口报错41001
18 Lectures on Disassembly of Multi-merchant Mall System Functions
Go language serialization and deserialization and how to change the uppercase of the json key value to lowercase if the json after serialization is empty
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
能源企业数字化转型背景下的数据安全治理实践路径
vim相关介绍(二)









