LCT 10pts 求助

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

jqsh @ 2023-10-05 18:45:55

#include <bits/stdc++.h>
#define db double
using namespace std;
int n, ans, cnt;
int lt[10240001];
struct Node {
    double k, b;
} Q[10240001];
void pushdown(int k, int l, int r, int s) {
    int mid = (l + r) >> 1;
    db ls = (db)l * Q[s].k + Q[s].b, rs = (db)r * Q[s].k + Q[s].b;
    db lk = (db)l * Q[lt[k]].k + Q[lt[k]].b, rk = (db)r * Q[lt[k]].k + Q[lt[k]].b;
    db smid = (db)mid * Q[s].k + Q[s].b;
    db kmid = (db)mid * Q[lt[k]].k + Q[lt[k]].b;

    if (ls > lk && rs > rk) {
        lt[k] = s;
        return;
    }

    if (ls < lk && rs < rk) {
        return;
    }
    if(l>=r) return;
    if ((ls >= lk && smid > kmid) || (ls > lk && smid >= kmid)) {
        pushdown(k << 1, l, mid, s);
    } else if (ls > lk || smid > kmid) {
        pushdown(k << 1, l, mid, lt[k]);
        pushdown(k << 1, l, mid, s);
    }

    if ((smid >= kmid && rs > rk) || ((smid > kmid && rs >= rk))) {
        pushdown(k << 1 | 1, mid + 1, r, s);
    } else if (smid > kmid || rs > rk) {
        pushdown(k << 1 | 1, mid + 1, r, lt[k]);
        pushdown(k << 1 | 1, mid + 1, r, s);
    }

    return;
}
void add(int k, int l, int r, int x, int y, int s) {
    if (l > y || r < x)
        return;

    if (l >= x && r <= y) {
        int mid=(l+r)>>1;
        pushdown(k << 1, l, mid, lt[k]);
        pushdown(k << 1 | 1, mid + 1, r, lt[k]);
        pushdown(k, l, r, s);
        return;
    }

    int mid = (l + r) >> 1;
    pushdown(k << 1, l, mid, lt[k]);
    pushdown(k << 1 | 1, mid + 1, r, lt[k]);
    add(k << 1, l, mid, x, y, s);
    add(k << 1 | 1, mid + 1, r, x, y, s);
    return;
}
void query(int k, int l, int r, int x) {
    if (l > x || r < x)
        return;

    if (l == r && l == x) {
        printf("%d\n", lt[k]);
        ans = lt[k];
        return;
    }

    int mid = (l + r) >> 1;
    pushdown(k << 1, l, mid, lt[k]);
    pushdown(k << 1 | 1, mid + 1, r, lt[k]);
    query(k << 1, l, mid, x);
    query(k << 1 | 1, mid + 1, r, x);
    return;
}
signed main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        int op;
        cin >> op;

        if (!op) {
            int k;
            cin >> k;
            k = (k + ans - 1 + 39989) % 39989 + 1;
            query(1, 1, 39989, k);
        } 
        else {
            cnt++;
            double a = 0, b = 0, c = 0, d = 0;
            cin >> a >> b >> c >> d;

            if (a > c) {
                swap(a, c);
                swap(b, d);
            }

            a = ((int)((int)a + ans - 1 + 39989) % (int)39989) + 1;
            b = ((int)((int)b + ans - 1 + 1e9) % (int)1e9) + 1;
            c = ((int)((int)c + ans - 1 + 39989) % (int)39989) + 1;
            d = ((int)((int)d + ans - 1 + 1e9) % (int)1e9) + 1;

            if (a == c) {
                Q[cnt].k = 0;
                Q[cnt].b = max(b, d);
            } else {
                db K = (d - b) / (c - a);
                db B;
                B = b - a * K;
                Q[cnt].b = B;
                Q[cnt].k = K;
            }
            add(1, 1, 39989, a, c, cnt);
        }
    }

    return 0;
}

已经调了一个月了 救救萌新把 QAQ


by YukinoYukinoshita @ 2023-10-05 19:43:11

我也没看懂你在写啥,感觉和主流写法不大一样


by YukinoYukinoshita @ 2023-10-05 19:45:26

不过如果你的lt的含义如果是当前mid这个点的最优直线的话,你得一路对访问到得直线取max


by YukinoYukinoshita @ 2023-10-05 19:45:47

@jqsh


by YukinoYukinoshita @ 2023-10-05 19:47:52

话说你这样写时间复杂度没问题吗


by YukinoYukinoshita @ 2023-10-05 19:56:09

...


by YukinoYukinoshita @ 2023-10-05 19:56:53

@jqsh 有没有可能你解密错了,交换a,c要放在后面


by YukinoYukinoshita @ 2023-10-05 19:59:06

就是这个问题,还有个hack数据你自己调把


by jqsh @ 2023-10-05 20:44:01

@YukinoYukinoshita 好的,谢谢巨佬 奶茶可以加我QQ


上一页 |