求助片段

P4513 小白逛公园

Tomotake @ 2024-12-14 15:45:41

一:

struct Tree
    {
        int l, r, lv, rv, v, s;
    }

Tree query(int u, int l, int r)
    {
        if (tr[u].l >= l && tr[u].r <= r) return tr[u];
        else
        {
            int mid = (tr[u].l + tr[u].r) >> 1;
            if (r <= mid) return query(ls, l, r);
            else if (l > mid) return (query(rs, l, r));
            else
            {
                Tree left = query(ls, l, r), right = query(rs, l, r), res;
                pushup(res, left, right);
                return res;
            }
        }
    }

二:

struct Tree
    {
        int l, r, lv, rv, v, s;
    }

Tree query(int u, int l, int r)
    {
        Tree res = {0, 0, 0, 0, 0, 0};
        if (tr[u].l > r || tr[u].r < l) return res;
        if (tr[u].l >= l && tr[u].r <= r) return tr[u];
        Tree L = query(ls, l, r), R = query(rs, l, r);
        pushup(res, L, R);
        return res;
    }

为什么递归方式会导致第一种方式正确第二种错误?


|