当前位置:网站首页>[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;
}
边栏推荐
- EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
- Laravel 预防 SQL 注入
- i.MX6U-driver development-3-new character driver
- Elephant Swap: Provide arbitrage space in the crypto market with ePLATO
- EA&UML日拱一卒-多任务编程超入门-(2)进程和线程
- CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
- UE4 制作十字准心+后坐力
- 新媒体运营必备的4个热点查询网
- 【分层强化学习】survey
- EA&UML日拱一卒-状态图::重画按钮状态图
猜你喜欢

Worthington's tried and tested cell isolation system protocols
![[Cloud native Kubernetes] Build a Kubernetes cluster in binary (middle) - deploy node nodes](/img/07/7f19751f4eadf9fd5612f56d1936d1.png)
[Cloud native Kubernetes] Build a Kubernetes cluster in binary (middle) - deploy node nodes

vmtouch——Linux下的文件缓存管理神器

绘制几何图形

News text classification

第一范式、第二范式、第三范式

低压差线性稳压器MPQ2013A-AEC1品牌MPS国产替代

Worthington Optimized Technology: Cell Quantification

Toutiao We-Media Operation: How to Gain 500+ Fans in Toutiao Today?

循环神经网络(RNN)
随机推荐
EA&UML日拱一卒-多任务编程超入门-(9)线程同步
Override and customize dependent native Bean methods
Sentinel入门
中文语义匹配
关于MySQL索引的一些个人理解(部分参考MySQL45讲)
EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
557. 反转字符串中的单词 III
docker安装redis集群(含部署脚本)
BEVDetNet: Bird's Eye View LiDAR Point Cloud based Real-time 3D Object Detection for Autonomous Drivi
窗口函数笔记
Replace the executable file glibc version of the one
『牛客|每日一题』走迷宫
Codeforces Round #805 (Div. 3)总结
Worthington's tried and tested cell isolation system protocols
EA&UML日拱一卒-多任务编程超入门-(2)进程和线程
从尾到头打印链表
First Normal Form, Second Normal Form, Third Normal Form
ZLMediaKit源码分析 - NotifyCenter
The difference and usage of call, apply and bind
关于 byte 的范围