結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー sotanishysotanishy
提出日時 2022-06-17 22:21:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 588 ms / 3,000 ms
コード長 3,960 bytes
コンパイル時間 3,271 ms
コンパイル使用メモリ 222,736 KB
実行使用メモリ 39,140 KB
最終ジャッジ日時 2024-04-17 14:27:52
合計ジャッジ時間 16,796 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 32 ms
29,568 KB
testcase_03 AC 164 ms
30,848 KB
testcase_04 AC 190 ms
16,868 KB
testcase_05 AC 225 ms
18,020 KB
testcase_06 AC 319 ms
31,244 KB
testcase_07 AC 414 ms
30,948 KB
testcase_08 AC 236 ms
21,860 KB
testcase_09 AC 318 ms
33,336 KB
testcase_10 AC 304 ms
19,684 KB
testcase_11 AC 176 ms
12,004 KB
testcase_12 AC 301 ms
21,096 KB
testcase_13 AC 128 ms
10,596 KB
testcase_14 AC 219 ms
9,576 KB
testcase_15 AC 143 ms
11,360 KB
testcase_16 AC 304 ms
28,900 KB
testcase_17 AC 515 ms
34,272 KB
testcase_18 AC 437 ms
33,768 KB
testcase_19 AC 511 ms
34,916 KB
testcase_20 AC 80 ms
26,880 KB
testcase_21 AC 156 ms
31,112 KB
testcase_22 AC 166 ms
11,108 KB
testcase_23 AC 106 ms
18,712 KB
testcase_24 AC 152 ms
8,676 KB
testcase_25 AC 412 ms
23,012 KB
testcase_26 AC 438 ms
32,992 KB
testcase_27 AC 80 ms
7,776 KB
testcase_28 AC 153 ms
34,304 KB
testcase_29 AC 447 ms
39,008 KB
testcase_30 AC 320 ms
38,288 KB
testcase_31 AC 274 ms
34,304 KB
testcase_32 AC 588 ms
39,140 KB
testcase_33 AC 543 ms
38,116 KB
testcase_34 AC 469 ms
38,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

template <typename M, typename O, typename M::T (*act)(typename M::T, typename O::T)>
class LazySegmentTree {
    using T = typename M::T;
    using E = typename O::T;

public:
    LazySegmentTree() = default;
    explicit LazySegmentTree(int n) : LazySegmentTree(std::vector<T>(n, M::id())) {}
    explicit LazySegmentTree(const std::vector<T>& v) {
        size = 1;
        while (size < (int) v.size()) size <<= 1;
        node.resize(2 * size, M::id());
        lazy.resize(2 * size, O::id());
        std::copy(v.begin(), v.end(), node.begin() + size);
        for (int i = size - 1; i > 0; --i) node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }

    T operator[](int k) {
        return fold(k, k + 1);
    }

    void update(int l, int r, const E& x) { update(l, r, x, 1, 0, size); }

    T fold(int l, int r) { return fold(l, r, 1, 0, size); }

private:
    int size;
    std::vector<T> node;
    std::vector<E> lazy;

    void push(int k) {
        if (lazy[k] == O::id()) return;
        if (k < size) {
            lazy[2 * k] = O::op(lazy[2 * k], lazy[k]);
            lazy[2 * k + 1] = O::op(lazy[2 * k + 1], lazy[k]);
        }
        node[k] = act(node[k], lazy[k]);
        lazy[k] = O::id();
    }

    void update(int a, int b, const E& x, int k, int l, int r) {
        push(k);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] = O::op(lazy[k], x);
            push(k);
            return;
        }
        int m = (l + r) / 2;
        update(a, b, x, 2 * k, l, m);
        update(a, b, x, 2 * k + 1, m, r);
        node[k] = M::op(node[2 * k], node[2 * k + 1]);
    }

    T fold(int a, int b, int k, int l, int r) {
        push(k);
        if (r <= a || b <= l) return M::id();
        if (a <= l && r <= b) return node[k];
        int m = (l + r) / 2;
        return M::op(fold(a, b, 2 * k, l, m),
                     fold(a, b, 2 * k + 1, m, r));
    }
};

struct AddMonoid {
    using T = ll;
    static T id() { return 0; }
    static T op(T a, T b) {
        return a + b;
    }
};

struct MinMonoid {
    using T = pair<ll, int>;
    static T id() { return {1e18, -1}; }
    static T op(T a, T b) {
        return min(a, b);
    }
};

pair<ll, int> act(pair<ll, int> a, ll b) {
    return {a.first+b, a.second};
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<tuple<int, int, int, ll>> ops;
    rep(_,0,K) {
        int l, r, c;
        ll h;
        cin >> l >> r >> c >> h;
        ops.push_back({l-1, r, c, h});
    }
    vector<vector<pair<ll, int>>> queries(N);
    rep(q,0,Q) {
        int i;
        ll x;
        cin >> i >> x;
        --i;
        queries[i].push_back({x, q});
    }

    vector<pair<ll, int>> init(N);
    rep(i,0,N) {
        queries[i].push_back({1e18, -1});
        sort(all(queries[i]));
        reverse(all(queries[i]));
        auto [x, q] = queries[i].back();
        init[i] = {x, i};
    }
    LazySegmentTree<MinMonoid, AddMonoid, act> st(init);
    vector<int> ans(Q, -1);
    for (auto [l, r, c, h] : ops) {
        st.update(l, r, -h);
        while (true) {
            auto [x, i] = st.fold(0, N);
            if (x <= 0) {
                auto [y, q] = queries[i].back();
                queries[i].pop_back();
                st.update(i, i+1, queries[i].back().first-y);
                ans[q] = c;
            } else {
                break;
            }
        }
    }
    rep(i,0,Q) cout << ans[i] << "\n";
}
0