結果

問題 No.1234 典型RMQ
ユーザー りあんりあん
提出日時 2020-09-19 00:56:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 2,684 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 201,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 11:20:46
合計ジャッジ時間 8,304 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 195 ms
5,376 KB
testcase_07 AC 166 ms
5,376 KB
testcase_08 AC 205 ms
5,376 KB
testcase_09 AC 181 ms
5,376 KB
testcase_10 AC 195 ms
5,376 KB
testcase_11 AC 190 ms
5,376 KB
testcase_12 AC 180 ms
5,376 KB
testcase_13 AC 168 ms
5,376 KB
testcase_14 AC 181 ms
5,376 KB
testcase_15 AC 177 ms
5,376 KB
testcase_16 AC 203 ms
5,376 KB
testcase_17 AC 177 ms
5,376 KB
testcase_18 AC 154 ms
5,376 KB
testcase_19 AC 204 ms
5,376 KB
testcase_20 AC 148 ms
5,376 KB
testcase_21 AC 192 ms
5,376 KB
testcase_22 AC 183 ms
5,376 KB
testcase_23 AC 182 ms
5,376 KB
testcase_24 AC 184 ms
5,376 KB
testcase_25 AC 184 ms
5,376 KB
testcase_26 AC 185 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
long long LM = 1LL << 60;

class sqrt_decomp {
    class node {
        int l, r;
        vector<long long> raw;
        long long ad;
        long long res;

        inline void eval_all() {
            res = LM;
            for (auto& i : raw) {
                i += ad;
                res = min(res, i);
            }
            ad = 0;
        }

    public:
        node(const vector<long long>& v, int l, int r) : l(l), r(r), ad(0), res(LM) {
            raw = vector<long long>(r - l);
            for (int i = l; i < r; ++i) {
                raw[i - l] = v[i];
                res = min(res, v[i]);
            }
        }

        inline long long calc(int _l, int _r) {
            if (r <= _l || _r <= l) {
                return LM;
            }
            else if (_l <= l && r <= _r) {
                return res;
            }
            else {
                eval_all();
                long long res = LM;
                for (int i = max(l, _l); i < min(r, _r); ++i) {
                    res = min(res, raw[i - l]);
                }
                return res;
            }
        }
        inline void update(int _l, int _r, long long _ad) {
            if (r <= _l || _r <= l) {
                return;
            }
            else if (_l <= l && r <= _r) {
                res += _ad;
                ad += _ad;
            }
            else {
                // eval_all();
                for (int i = max(l, _l); i < min(r, _r); ++i) {
                    raw[i - l] += _ad;
                }
                eval_all();
            }
        }
    };

    vector<node> v;

public:
    sqrt_decomp(const vector<long long>& a, int bucket_size) {
        v = vector<node>();
        for (int i = 0; i < (int)a.size(); i += bucket_size) {
            v.emplace_back(a, i, min(i + bucket_size, (int)a.size()));
        }
    }
    void update(int l, int r, long long ad) {
        for (auto& i : v) {
            i.update(l, r, ad);
        }
    }
    long long run(int l, int r) {
        long long res = LM;
        for (auto& i : v) {
            res = min(res, i.calc(l, r));
        }
        return res;
    }
};



int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sqrt_decomp sd(a, 300);
    int q;
    cin >> q;
    for (int _ = 0; _ < q; ++_) {
        int t, l, r, c;
        cin >> t >> l >> r >> c;
        --l;
        if (t == 1) {
            sd.update(l, r, c);
        }
        else {
            cout << sd.run(l, r) << '\n';
        }
    }
    return 0;
}
0