QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787491#8522. Waterfall Matrixucup-team004Compile Error//C++236.9kb2024-11-27 12:14:372024-11-27 12:14:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 12:14:39]
  • 评测
  • [2024-11-27 12:14:37]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

template<class Info, class Tag>
struct LazySegmentTree {
    int n;
    std::vector<Info> info;
    std::vector<Tag> tag;
    LazySegmentTree() : n(0) {}
    LazySegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    LazySegmentTree(std::vector<T> init_) {
        init(init_);
    }
    void init(int n_, Info v_ = Info()) {
        init(std::vector(n_, v_));
    }
    template<class T>
    void init(std::vector<T> init_) {
        n = init_.size();
        info.assign(4 << std::__lg(n), Info());
        tag.assign(4 << std::__lg(n), Tag());
        std::function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (r - l == 1) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m, r);
            pull(p);
        };
        build(1, 0, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void apply(int p, const Tag &v) {
        info[p].apply(v);
        tag[p].apply(v);
    }
    void push(int p) {
        apply(2 * p, tag[p]);
        apply(2 * p + 1, tag[p]);
        tag[p] = Tag();
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (r - l == 1) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        push(p);
        if (x < m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 0, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l >= y || r <= x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        push(p);
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 0, n, l, r);
    }
    void rangeApply(int p, int l, int r, int x, int y, const Tag &v) {
        if (l >= y || r <= x) {
            return;
        }
        if (l >= x && r <= y) {
            apply(p, v);
            return;
        }
        int m = (l + r) / 2;
        push(p);
        rangeApply(2 * p, l, m, x, y, v);
        rangeApply(2 * p + 1, m, r, x, y, v);
        pull(p);
    }
    void rangeApply(int l, int r, const Tag &v) {
        return rangeApply(1, 0, n, l, r, v);
    }
    template<class F>
    int findFirst(int p, int l, int r, int x, int y, F &&pred) {
        if (l >= y || r <= x) {
            return -1;
        }
        if (l >= x && r <= y && !pred(info[p])) {
            return -1;
        }
        if (r - l == 1) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findFirst(2 * p, l, m, x, y, pred);
        if (res == -1) {
            res = findFirst(2 * p + 1, m, r, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findFirst(int l, int r, F &&pred) {
        return findFirst(1, 0, n, l, r, pred);
    }
    template<class F>
    int findLast(int p, int l, int r, int x, int y, F &&pred) {
        if (l >= y || r <= x) {
            return -1;
        }
        if (l >= x && r <= y && !pred(info[p])) {
            return -1;
        }
        if (r - l == 1) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findLast(2 * p + 1, m, r, x, y, pred);
        if (res == -1) {
            res = findLast(2 * p, l, m, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findLast(int l, int r, F &&pred) {
        return findLast(1, 0, n, l, r, pred);
    }
};

constexpr int inf = 1E9;

struct Tag {
    bool s = false;
    int v = 0;
    int a = 0;
    void apply(const Tag &t) & {
        if (t.s) {
            s = true;
            v = t.v;
            a = 0;
        }
        a += t.a;
    }
};

struct Info {
    int x = -inf;
    int id = -1;
    void apply(const Tag &t) & {
        if (t.s) {
            x = t.v;
            id = -1;
        }
        x += t.a;
    }
};

Info operator+(const Info &a, const Info &b) {
    if (a.x >= b.x) {
        return a;
    } else {
        return b;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i] >> c[i];
    }
    
    auto vb = b;
    std::sort(vb.begin(), vb.end());
    for (int i = 0; i < n; i++) {
        b[i] = std::lower_bound(vb.begin(), vb.end(), b[i]) - vb.begin();
    }
    
    auto val = c;
    std::sort(val.begin(), val.end());
    val.erase(std::unique(val.begin(), val.end()), val.end());
    for (int i = 0; i < n; i++) {
        c[i] = std::lower_bound(val.begin(), val.end(), c[i]) - val.begin();
    }
    
    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 0);
    
    i64 ans = 0;
    
    std::vector<int> g(n);
    int m = val.size();
    LazySegmentTree<Info, Tag> seg(n);
    auto work = [&](this auto &&self, std::vector<int> p, int vl, int vr) {
        std::sort(p.begin(), p.end());
        if (vl == vr) {
            for (auto i : p) {
                ans += std::abs(val[c[i]] - val[vl]);
            }
            return;
        }
        int vm = (vl + vr) / 2;
        
        std::sort(p.begin(), p.end(),
            [&](int i, int j) {
                if (a[i] != a[j]) {
                    return a[i] < a[j];
                }
                return b[i] < b[j];
            });
        seg.rangeApply(0, n, {true, -inf});
        for (auto i : p) {
            int v = c[i] <= vm ? 1 : -1;
            auto [x, id] = seg.rangeQuery(b[i], n);
            if (x < 0) {
                x = 0;
                id = -1;
            }
            g[i] = id;
            seg.modify(b[i], {x, i});
            seg.rangeApply(0, b[i] + 1, {.a = v});
        }
        auto [x, lst] = seg.rangeQuery(0, n);
        if (x < 0) {
            x = 0;
            lst = -1;
        }
        
        std::vector<int> pl, pr;
        std::reverse(p.begin(), p.end());
        for (auto i : p) {
            if (lst != -1 && b[i] >= b[lst]) {
                pl.push_back(i);
            } else {
                pr.push_back(i);
            }
            if (i == lst) {
                lst = g[i];
            }
        }
        self(pl, vl, vm);
        self(pr, vm + 1, vr);
    };
    work(p, 0, m - 1);
    
    std::cout << ans << "\n";
    
    return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:218:21: error: expected identifier before ‘this’
  218 |     auto work = [&](this auto &&self, std::vector<int> p, int vl, int vr) {
      |                     ^~~~
answer.code:218:21: error: expected ‘,’ or ‘...’ before ‘this’
answer.code: In lambda function:
answer.code:220:13: error: ‘vl’ was not declared in this scope; did you mean ‘val’?
  220 |         if (vl == vr) {
      |             ^~
      |             val
answer.code:220:19: error: ‘vr’ was not declared in this scope; did you mean ‘vb’?
  220 |         if (vl == vr) {
      |                   ^~
      |                   vb
answer.code:226:19: error: ‘vl’ was not declared in this scope; did you mean ‘val’?
  226 |         int vm = (vl + vr) / 2;
      |                   ^~
      |                   val
answer.code:226:24: error: ‘vr’ was not declared in this scope; did you mean ‘vb’?
  226 |         int vm = (vl + vr) / 2;
      |                        ^~
      |                        vb
answer.code:265:9: error: ‘self’ was not declared in this scope
  265 |         self(pl, vl, vm);
      |         ^~~~
answer.code: In function ‘int main()’:
answer.code:268:9: error: no match for call to ‘(main()::<lambda(int)>) (std::vector<int>&, int, int)’
  268 |     work(p, 0, m - 1);
      |     ~~~~^~~~~~~~~~~~~
answer.code:218:17: note: candidate: ‘main()::<lambda(int)>’
  218 |     auto work = [&](this auto &&self, std::vector<int> p, int vl, int vr) {
      |                 ^
answer.code:218:17: note:   candidate expects 1 argument, 3 provided