Submission #1091955

# Submission time Handle Problem Language Result Execution time Memory
1091955 2024-09-22T17:19:08 Z huyngo Wall (IOI14_wall) C++17
32 / 100
413 ms 34616 KB
#include "wall.h"
#include <bits/stdc++.h>  
using namespace std;
using ll = long long;
using i64 = long long;
void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '"' << x << '"'; } void __print(const string& x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define ln "\n"
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define ar array
int Bit(int mask, int b) { return (mask >> b) & 1; }
const ll base = 311, MOD = 998244353, M = 1e9 + 7, INF = 1e18;

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);
    }
    // note: query on [l,r)
    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);
    }
    // note: apply on [l,r)
    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 || !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 || !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 i64 inf = 1E18;
struct Tag {
    i64 lz = 0;
    int lastAdd = 0;
    void apply(Tag t) {
        lz = max(lz, t.lz);
        lastAdd = max(lastAdd, t.lastAdd);
    }
};

struct Tag2 {
    i64 lz = inf;
    void apply(Tag2 t) {
        lz = min(lz, t.lz);
    }
};

struct Info {
    i64 max = -inf;
    i64 min = inf;
    void apply(Tag t) {
        max = std::max(max, t.lz);
        min = std::min(min, t.lz);
    }
    void apply(Tag2 t) {
        max = std::max(max, t.lz);
        min = std::min(min, t.lz);
    }
};

Info operator+(Info a, Info b) {
    Info c;
    c.max = std::max(a.max, b.max);
    c.min = std::min(a.min, b.min);
    return c;
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    if (k <= 5000) {
        rep(i, 0, k - 1) {
            if (op[i] == 1)
                rep(j, left[i], right[i])
                finalHeight[j] = max(finalHeight[j], height[i]);
            else
                rep(j, left[i], right[i])
                finalHeight[j] = min(finalHeight[j], height[i]);
        }
        return;
    }
    LazySegmentTree<Info, Tag> add(n, Info{ 0,0 });
    rep(i, 0, k - 1) {
        if (op[i] == 1)
            add.rangeApply(left[i], right[i] + 1, Tag{ height[i] });
    }
    LazySegmentTree<Info, Tag2> rem(n);
    rep(i, 0, n - 1) {
        int x = add.rangeQuery(i, i + 1).max;
        rem.modify(i, Info{ x,x });
    }
    rep(i, 0, k - 1)
        if (op[i] == 2) {
            rem.rangeApply(left[i], right[i] + 1, Tag2{ height[i] });
        }
    rep(i, 0, n - 1)
        finalHeight[i] = rem.rangeQuery(i, i + 1).min;
    return;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 632 KB Output is correct
5 Correct 18 ms 660 KB Output is correct
6 Correct 16 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 90 ms 13908 KB Output is correct
3 Correct 138 ms 11316 KB Output is correct
4 Correct 413 ms 34040 KB Output is correct
5 Correct 287 ms 34616 KB Output is correct
6 Correct 274 ms 33080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 18 ms 636 KB Output is correct
5 Correct 13 ms 632 KB Output is correct
6 Correct 13 ms 636 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 83 ms 13820 KB Output is correct
9 Correct 139 ms 11316 KB Output is correct
10 Correct 402 ms 33992 KB Output is correct
11 Correct 290 ms 34612 KB Output is correct
12 Correct 304 ms 33112 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 85 ms 13900 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 640 KB Output is correct
5 Correct 13 ms 604 KB Output is correct
6 Correct 13 ms 640 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 83 ms 13860 KB Output is correct
9 Correct 139 ms 11372 KB Output is correct
10 Correct 411 ms 34028 KB Output is correct
11 Correct 290 ms 34616 KB Output is correct
12 Correct 273 ms 33156 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 87 ms 13820 KB Output isn't correct
15 Halted 0 ms 0 KB -