萌新求助挂七个点

P4097 【模板】李超线段树 / [HEOI2013] Segment

Register_int @ 2022-08-18 08:33:50

rt.调了好久没调出来,想请大佬帮忙看下

#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef pair<db, int> pdbi;

const int MAXN = 1e5 + 10;
const int mod1 = 39989;
const int mod2 = 1e9;

struct line {
    db k, b;
} q[MAXN];

int t[MAXN << 2], tot;

inline 
int cmp(db x, db y) {
    if (fabs(x - y) < 1e-9) return 0;
    return x - y > 1e-9 ? 1 : -1;
}

inline 
pdbi cmax(pdbi x, pdbi y) {
    int pl = cmp(x.first, y.first);
    if (!pl) return x.second < y.second ? x : y;
    return pl > 0 ? x : y;
}

inline 
double calc(int p, int x) {
    return q[p].k * x + q[p].b;
}

inline 
void add(int ax, int ay, int bx, int by) {
    if (ax == bx) q[++tot] = { 0, max(ay, by) };
    else q[++tot].k = (ay - by) / (ax - bx), q[tot].b = ay - q[tot].k * ax;
}

void pushdown(int l, int r, int u, int p) {
    int mid = l + r >> 1;
    if (calc(u, mid) > calc(t[p], mid)) swap(u, t[p]);
    int bl = cmp(calc(u, l), calc(t[p], l)), br = cmp(calc(u, r), calc(t[p], r));
    if (bl > 0 || (!bl && u < t[p])) pushdown(l, mid, u, p << 1);
    if (br > 0 || (!br && u < t[p])) pushdown(mid + 1, r, u, p << 1 | 1);
}

void modify(int l, int r, int ql, int qr, int u, int p) {
    if (ql <= l && r <= qr) return pushdown(l, r, u, p);
    int mid = l + r >> 1;
    if (ql <= mid) modify(l, mid, ql, qr, u, p << 1);
    if (qr > mid) modify(mid + 1, r, ql, qr, u, p << 1 | 1);
}

pdbi query(int l, int r, int x, int p) {
//  printf("%d %d %d %d\n", l, r, x, p);
    if (x < l || r < x) return { 0, 0 };
    int mid = l + r >> 1;
    db res = calc(t[p], x);
    if (l == r) return { res, t[p] };
    return cmax({ res, t[p] }, cmax(query(l, mid, x, p << 1), query(mid + 1, r, x, p << 1 | 1)));
}

int last;

int n, opt;

int k, ax, ay, bx, by;

int main() {
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &opt);
        if (opt == 1) {
            scanf("%d%d%d%d", &ax, &ay, &bx, &by);
            ax = (ax + last - 1 + mod1) % mod1 + 1;
            bx = (bx + last - 1 + mod1) % mod1 + 1;
            ay = (ay + last - 1 + mod2) % mod2 + 1;
            by = (by + last - 1 + mod2) % mod2 + 1;
            if (ax > bx) swap(ax, bx), swap(ay, by);
            add(ax, ay, bx, by), modify(1, mod1, ax, bx, tot, 1);
        } else {
            scanf("%d", &k);
            k = (k + last - 1 + mod1) % mod1 + 1;
            printf("%d\n", last = query(1, mod1, k, 1).second);
        }
    }
}

by Register_int @ 2022-08-18 19:02:58

破案了,没转double。留一个警示后人吧


|