社区讨论

萌新刚学K-DTree2WA2RE求调

P4148简单题参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lyo3lll4
此快照首次捕获于
2024/07/16 15:34
2 年前
此快照最后确认于
2024/07/16 15:39
2 年前
查看原帖
CPP

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>

#define int long long
#define function auto
#define rop(a, b, c) for(int a = b;a < c; ++ a)
#define por(a, b, c) for(int a = b;a > c; -- a)
#define rep(a, b, c) for(int a = b;a <= c; ++ a)
#define per(a, b, c) for(int a = b;a >=c ; -- a)

typedef long long LL;

constexpr int N = 2e5 + 10, LG = 15;

namespace Space {

    function max = [](int a, int b) -> int {
        return a > b ? a : b;
    };

    template < typename _Tp > inline
    function read(_Tp& t) -> void {
        int f = 0, ch = getchar ();t = 0;
        while (!isdigit(ch)) f |= ch == '-', ch = getchar ();
        do{t = (t << 1) + (t << 3) + (ch ^ '0'); ch  = getchar ();}
        while (isdigit(ch));if (f) t = -t;
    }
    
    template < typename _Tp, typename... Args > inline
    function read(_Tp& t, Args&... args) -> void {
        read(t);read(args...);
    }
}

using namespace Space;

struct Pt {
    int x[2], v, sum;
    int l, r;
    int L[2], R[2];

}t[N], l, h;

int rt[LG];
int b[N], cnt;

class Solve {
private:
    inline function
    upd(int p) -> void {
        t[p].sum = t[t[p].l].sum + t[t[p].r].sum + t[p].v;
        for (auto k : {0, 1}) {
            t[p].L[k] = t[p].R[k] = t[p].x[k]; if (t[p].l) {
                t[p].L[k] = std::min(t[p].L[k], t[t[p].l].L[k]);
                t[p].R[k] = std::max(t[p].R[k], t[t[p].l].R[k]);
            } if (t[p].r) {
                t[p].L[k] = std::min(t[p].L[k], t[t[p].r].L[k]);
                t[p].R[k] = std::max(t[p].R[k], t[t[p].r].R[k]);
            }
        }
    }
    inline function
    build(int l, int r, int dep = 0) -> int {
        int p = (l + r) >> 1;
        std::nth_element(b + l, b + p, b + r + 1, [dep](int x, int y) {
            return t[x].x[dep] < t[y].x[dep];
        }); int x = b[p];
        if (l < p) t[x].l = this -> build(l, p - 1, dep ^ 1);
        if (p < r) t[x].r = this -> build(p + 1, r, dep ^ 1);
        this -> upd(x);return x;
    }

    inline function
    append(int& p) -> void {
        if (!p) return;
        b[ ++ cnt] = p;
        this -> append(t[p].l);
        this -> append(t[p].r);
        p = 0;
    }

    inline function
    query(int p) ->int {
        if (!p) return{0};
        bool flag = false;
        for (auto k : {0, 1}) 
            flag |= (!(l.x[k] <= t[p].L[k] && t[p].R[k] <= h.x[k]));
        if (!flag) return{t[p].sum};
        for (auto k : {0, 1})
            if (t[p].R[k] < l.x[k] || h.x[k] < t[p].L[k]) return{0};  
        int ans = 0; flag = false;
        for (auto k : {0, 1}) 
            flag |= (!(l.x[k] <= t[p].x[k] && t[p].x[k] <= h.x[k]));
        if (!flag) ans = t[p].v;
        return ans += this -> query(t[p].l) + this -> query(t[p].r);
    }
public:
    inline function
    solve () {
        int n;read(n);
        int lst = 0; n = 0;
        while (true) {
            int op;read(op);
            if (op == 1) {
                int x, y, A;read(x, y, A);
                x ^= lst; y ^= lst; A ^= lst;
                t[++n] = {{x, y}, A};
                b[cnt = 1] = n;
                for (auto sz = 0; ; ++sz)
                    if (!rt[sz]) {
                        rt[sz] = build(1, cnt);
                        break;
                    } else append(rt[sz]);
                } else if (op == 2) {
                    read(l.x[0], l.x[1], h.x[0], h.x[1]);
                    l.x[0] ^= lst; l.x[1] ^= lst;
                    h.x[0] ^= lst; h.x[1] ^= lst;
                    lst = 0; rop(i, 0, LG) 
                        lst += this -> query(rt[i]);
                    std:: cout << lst << "\n";
                } else break;
        }
    }
}T;

signed main() {
    T.solve();
}

回复

0 条回复,欢迎继续交流。

正在加载回复...