当前位置:网站首页>[Training DAY16] ALFA [convex hull] [computational geometry]
[Training DAY16] ALFA [convex hull] [computational geometry]
2022-07-30 00:13:00 【VL - MOESR】

思路:
At the same time divided by the firstx,Then with the convex hull maintenance,The answer on binary in a
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;
}
边栏推荐
- Since the media how to write a short video title?Three hot style title, let your video gain more traffic
- 读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》
- 第一范式、第二范式、第三范式
- How to design and implement report collaboration system for instruction set data products——Development practice of industrial collaborative manufacturing project based on instruction set IoT operating
- One article to answer web performance optimization
- CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
- 论文精读——YOLOv3: An Incremental Improvement
- 基于TNEWS‘ 今日头条中文新闻(短文本)分类
- 2022/7/29 考试总结
- 指令集数据产品如何设计和实现报表协同系统——基于指令集物联网操作系统的工业协同制造项目开发实践
猜你喜欢

Weekly recommended short video: What is R&D efficiency?It can achieve anti "involution"?

【云原生Kubernetes】二进制搭建Kubernetes集群(中)——部署node节点

Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles

【集训DAY16】KC ‘ s Stars【dfs】
Comprehensive Practice - Three-Mison Chess Mini Game

CNN的粗浅理解

头条号自媒体运营:如何在今日头条涨500+粉丝?

Worthington酶促细胞收获&细胞粘附和收获

KDE Frameworks 5.20.0:Plasma迎来诸多改进

i.MX6U-driver development-3-new character driver
随机推荐
c语言小游戏扫雷
循环神经网络(RNN)
YoloV5数据集自动划分训练集、验证集、测试集
i.MX6U-driver development-3-new character driver
call、apply 以及 bind 的区别和用法
Based on TNEWS 'today's headline news in Chinese short text classification
一文解答web性能优化
EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
微信开发者工具设置制表符大小为2
新媒体运营必备的4个热点查询网
Music theory & guitar skills
Paper Intensive Reading - YOLOv3: An Incremental Improvement
4 hotspot inquiry networks necessary for new media operations
"The lighthouse factory" of China path: smart roll out from point to surface
EA&UML日拱一卒-多任务编程超入门-(9)线程同步
How to increase account weight?3 ways to operate your own media to help you get more revenue
2022杭电多校第三场 Two Permutations (dp, 哈希)
rk-boot框架实战(1)
go语言序列化和反序列化及序列化后的json为空和json的key值大写如何改为小写问题
Unity Addressables