当前位置:网站首页>【集训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;
}
边栏推荐
- 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
- 指令集数据产品如何设计和实现报表协同系统——基于指令集物联网操作系统的工业协同制造项目开发实践
- PyTorch笔记 - Attention Is All You Need (1)
- Brute force recursion to dynamic programming 03 (knapsack problem)
- 全国双非院校考研信息汇总整理 Part.4
- Dropout回顾
- Reading notes. This is the psychology: see through the essence of the pseudo psychology (version 10)"
- Genesis与Axis Ventures互动密切
- 卧槽,2行代码,让接口性能提升10倍
- 决策树原理及代码实现
猜你喜欢

Why does LabVIEW freeze when saving a VI

Dropout回顾

Gao Shu Xia|Triple Integral Exercises|Uncle Gao Shu|Handwritten Notes

opencv基本图像的滤波

读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》

Brute force recursion to dynamic programming 04 (digital string conversion)

经典论文-SqueezeNet论文及实践

go语言(函数、闭包、defer、panic/recover,递归,结构体,json序列化与反序列化)

MySQL 用 BETWEEN AND 日期查询包含范围边界

绘制几何图形
随机推荐
接口性能测试方案设计方法有哪些?要怎么去写?
1326. 灌溉花园的最少水龙头数目 动态规划
UE4 makes crosshair + recoil
Framework 到底该怎么学习?
Why does LabVIEW freeze when saving a VI
「大厂必备」系列之Redis主从、持久化、哨兵
EA&UML日拱一卒-多任务编程超入门-(8)多任务安全的数据类
devops学习(八) 搭建镜像仓库---jenkins推送镜像
437. The total path III low low
C陷阱与缺陷 第4章 链接 4.1 什么是链接器
直播平台搭建,设置状态栏颜色
Override and customize dependent native Bean methods
Vulkan与OpenGL对比——Vulkan的全新渲染架构
High Numbers|Calculation of Triple Integral 3|Uncle High Numbers|Handwritten Notes
Paper Intensive Reading - YOLOv3: An Incremental Improvement
深度学习的随机种子
codeforces 线段树题单
管理区解耦架构见过吗?能帮客户解决大难题的
C陷阱与缺陷 第4章 链接 4.4 形参、实参与返回值
2022年企业直播行业发展洞察