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 jqsh @ 2023-10-05 18:49:30

悬关+15R奶茶


by embrace_corner @ 2023-10-05 18:52:56

调一个月!%%%orz


by OneSheeep @ 2023-10-05 19:05:45

日记(jc):你李超线段树哪来的pushdown啊,建议重写。


by jqsh @ 2023-10-05 19:05:55

巨佬们救救孩子吧 /(ㄒoㄒ)/~~


by jqsh @ 2023-10-05 19:06:34

@OneSheeep 只是更新的意思


by OneSheeep @ 2023-10-05 19:15:02

建议重构(


by OneSheeep @ 2023-10-05 19:15:47

@jqsh 还是jc:你更新咋写那么长,我也没写这么长啊。


by jqsh @ 2023-10-05 19:19:54

@OneSheeep 重构过好几遍了


by OneSheeep @ 2023-10-05 19:20:29

(惊恐


by YukinoYukinoshita @ 2023-10-05 19:42:29

是不是Query写错了


| 下一页