首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ZR#317.【18 提高 2】A(计算几何 二分)

ZR#317.【18 提高 2】A(计算几何 二分)

作者头像
attack
发布2018-09-17 15:37:25
2630
发布2018-09-17 15:37:25
举报

题意

Sol

非常好的一道题,幸亏这场比赛我没打,不然我估计要死在这个题上qwq

到不是说有多难,关键是细节太多了,我和wcz口胡了一下我的思路,然后他写了一晚上没调出来qwq

解法挺套路的,先提出一个$x$

然后维护一堆直线对应的上凸壳

在凸壳上二分即可。

由于这题的$x$很小,直接处理出答案就行了

/*

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long 
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7, BB = 32323;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
struct Node {
    double a, b;
    bool operator < (const Node &rhs) const {
        return a == rhs.a ? b < rhs.b : a < rhs.a;
    }
}P[MAXN], s1[MAXN], s2[MAXN];
int t1 = 0, t2 = 0, ans[MAXN];
double cross(Node x, Node y) {
//    printf("%lf\n", 1.0 * (y.b - x.b) / (x.a - x.b));
    return 1.0 * (y.b - x.b) / (x.a - y.a);
}
void Get() {
    sort(P + 1, P + N + 1);
    s1[++t1] = P[1];
    for(int i = 2; i <= N; i++) {
        if(t1 && P[i].a == s1[t1].a) t1--;
        while(t1 > 1 && cross(P[i], s1[t1]) <= cross(s1[t1], s1[t1 - 1])) t1--;
        s1[++t1] = P[i];
    }
    for(int i = 1; i <= N; i++) P[i].b = -P[i].b;
    sort(P + 1, P + N + 1);
    s2[++t2] = P[1];
    for(int i = 2; i <= N; i++) {
        if(t1 && P[i].a == s2[t2].a) t2--;
        while(t2 > 1 && cross(P[i], s2[t2]) <= cross(s2[t2], s2[t2 - 1])) t2--;
        s2[++t2] = P[i];
    }
}
int Query(Node p, int x) {
    return p.a * x * x + p.b * x;
}
void MakeAns() {
    for(int i = 1, c = 1; i <= BB; i++) {
        //printf("%lf\n", cross(s1[c], s1[c + 1]));
        while(c < t1 && cross(s1[c], s1[c + 1]) <= (double)i) c++;
        ans[i + BB] = Query(s1[c], i);
    }
    for(int i = 1, c = 1; i <= BB; i++) {
        while(c < t2 && cross(s2[c], s2[c + 1]) <= (double)i) c++;
        ans[BB - i] = Query(s2[c], i);
    }
}
main() {
//    freopen("a.in", "r", stdin);
    N = read(); int Q = read();
    for(int i = 1; i <= N; i++) P[i].a = read(), P[i].b = read();
    Get();
    MakeAns();
    while(Q--) {
        int x = read();
        printf("%lld\n", ans[x + BB]);
    }
    return 0;
}
/*
2 2 1
1 1
2 1 1
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-09-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档