奇怪的问题
查看原帖
奇怪的问题
258563
我是逍逍楼主2022/8/5 21:14

题目链接
提交记录

不知道为什么编译错误了,但是没有具体的错误信息,恳请 Dalao 解答,谢谢!

代码:

#include <iostream>

using namespace std;

const int Max = 500005;
const int Inf = 100000000;

int n, m, a[Max], b[Max];

struct SegmentTree {
    struct Node {
        int minB = Inf, maxA = -Inf, difA = -Inf, difB = -Inf, psi = -Inf;
    } tree[Max << 2];

#define maxA(p) (tree[p].maxA)
#define minB(p) (tree[p].minB)
#define difA(p) (tree[p].difA)
#define difB(p) (tree[p].difB)
#define psi(p) (tree[p].psi)
#define lCh (p << 1)
#define rCh (lCh | 1)
#define mid ((l + r) >> 1)

    void update(int p) {
        maxA(p) = max(maxA(lCh), maxA(rCh));
        minB(p) = min(minB(lCh), minB(rCh));
        difA(p) = max(max(difA(lCh), difA(rCh)), maxA(lCh) - minB(rCh));
        difB(p) = max(max(difB(lCh), difB(rCh)), maxA(rCh) - minB(lCh));
        psi(p) = max(max(psi(lCh), psi(rCh)), max(difA(lCh) + maxA(rCh), difB(rCh) + maxA(lCh)));
    }

    void build(int p, int l, int r) {
        if (l == r) {
            maxA(p) = a[l];
            minB(p) = b[l];
        } else {
            build(lCh, l, mid);
            build(rCh, mid + 1, r);
            update(p);
        }
    }

    void change(int p, int l, int r, int pos, int x, int y) {
        if (l == r) {
            if (x != -1)
                maxA(p) = x;
            else
                minB(p) = y;
        } else {
            if (pos <= mid)
                change(lCh, l, mid, pos, x, y);
            else
                change(rCh, mid + 1, r, pos, x, y);
            update(p);
        }
    }

    Node ask(int p, int l, int r, int x, int y) {
        if (x <= l && r <= y)
            return tree[p];
        Node s, t, ret;
        if (x <= mid)
            s = ask(lCh, l, mid, x, y);
        if (y > mid)
            t = ask(rCh, mid + 1, r, x, y);

        ret.maxA = max(s.maxA, t.maxA);
        ret.minB = min(s.minB, t.minB);
        ret.difA = max(max(s.difA, t.difA), s.maxA - t.minB);
        ret.difB = max(max(s.difB, t.difB), t.maxA - s.minB);
        ret.psi = max(max(s.psi, t.psi), max(s.difA + t.maxA, t.difB + s.maxA));
        return ret;
    }
} tree;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];

    tree.build(1, 1, n);

    for (int i = 1, op, x, y; i <= m; i++) {
        cin >> op >> x >> y;

        if (op == 1)
            tree.change(1, 1, n, x, y, -1);
        else if (op == 2)
            tree.change(1, 1, n, x, -1, y);
        else
            cout << tree.ask(1, 1, n, x, y).psi << '\n';
    }

    return 0;
}
  
2022/8/5 21:14
加载中...