답안 #1095734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095734 2024-10-03T04:06:24 Z eysbutno Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1232 ms 120808 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
 
template <class Info, class Tag> 
class LazySegtree {
  private:
    const int n;
    vector<Info> t;
    vector<Tag> lz;
       
    void build(int v, int l, int r, const vector<Info> &a) {
        if (l == r) {
            t[v] = a[l];
        } else {
            int m = (l + r) >> 1;
            build(2 * v, l, m, a);
            build(2 * v + 1, m + 1, r, a);
            t[v] = t[2 * v] + t[2 * v + 1];
        }
    }
 
    void apply(int v, int l, int r, const Tag &x) {
        t[v].apply(x, l, r);
        lz[v].apply(x);
    }
 
    void pushdown(int v, int l, int r) {
        int m = (l + r) >> 1;
        apply(2 * v, l, m, lz[v]);
        apply(2 * v + 1, m + 1, r, lz[v]);
        lz[v] = Tag();
    }
 
    void upd(int v, int l, int r, int ql, int qr, const Tag &x) {
        if (qr < l || ql > r) { return; }
        if (ql <= l && r <= qr) {
            apply(v, l, r, x);
        } else {
            pushdown(v, l, r);
            int m = (l + r) >> 1;
            upd(2 * v, l, m, ql, qr, x);
            upd(2 * v + 1, m + 1, r, ql, qr, x);
            t[v] = t[2 * v] + t[2 * v + 1];
        }
    }
    
    Info qry(int v, int l, int r, int ql, int qr) {
        if (qr < l || ql > r) return Info();
        if (l >= ql && r <= qr) return t[v];
        pushdown(v, l, r);
        int m = (l + r) >> 1;
        return qry(2 * v, l, m, ql, qr) + qry(2 * v + 1, m + 1, r, ql, qr);
    }
 
  public:
    LazySegtree() {}
    
    LazySegtree(int n) : n(n) {
        t.assign(4 << __lg(n), Info());
        lz.assign(4 << __lg(n), Tag());
    }
 
    LazySegtree(const vector<Info> &a) : n(a.size()) {
        t.assign(4 << __lg(n), Info());
        lz.assign(4 << __lg(n), Tag());
        build(1, 0, n - 1, a);
    }
 
    /** updates [ql, qr] with the arbitrary update chosen */
    void upd(int ql, int qr, const Tag &x) {
        upd(1, 0, n - 1, ql, qr, x);
    }
 
    /** @return result of range query on [ql, qr] */
    Info qry(int ql, int qr) {
        return qry(1, 0, n - 1, ql, qr);
    }
};
 
struct Tag {
    int st = -1;
    void apply(const Tag &t) {
        if (t.st != -1) {
            st = t.st;
        }
    }
};
 
struct Info {
    int mx = -1, applied = -1;
    void apply(const Tag &t, int l, int r) {
        if (t.st != -1) {
            applied = mx + t.st;
        }
    }
};
 
/** @return result of joining nodes a and b together */
Info operator+(const Info &a, const Info &b) {
    return {max(a.mx, b.mx), max(a.applied, b.applied)};
}
 
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> w(n);
    for (int &i : w) { cin >> i; }
    vector<Info> arr(n);
    for (int i = 0; i < n; i++) {
        arr[i] = {w[i], 0};
    }
    LazySegtree<Info, Tag> st(arr);
    vector<vector<array<int, 3>>> tests(n);
    for (int i = 0; i < q; i++) {
        int l, r, k;
        cin >> l >> r >> k;
        --l, --r;
        tests[l].push_back({r, k, i});
    }
    vector<bool> res(q);
    stack<int> stk;
    for (int i = n - 1; i >= 0; i--) {
        while (sz(stk) && w[stk.top()] <= w[i]) {
            stk.pop();
        }
        int b = stk.empty() ? n : stk.top();
        stk.push(i);
        if (i + 1 <= b - 1) { st.upd(i + 1, b - 1, {w[i]}); }
        for (const auto [r, k, idx] : tests[i]) {
            res[idx] = st.qry(i + 1, r).applied <= k;
        }
    }
    for (int i = 0; i < q; i++) {
        cout << res[i] << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 460 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 460 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1223 ms 115772 KB Output is correct
2 Correct 1214 ms 116932 KB Output is correct
3 Correct 1232 ms 116560 KB Output is correct
4 Correct 1182 ms 116604 KB Output is correct
5 Incorrect 954 ms 120808 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 77 ms 11348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 460 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 460 KB Output isn't correct
11 Halted 0 ms 0 KB -