結果

問題 No.1234 典型RMQ
ユーザー carrot46carrot46
提出日時 2020-09-18 23:13:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 2,206 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 170,780 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 11:18:16
合計ジャッジ時間 11,204 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 368 ms
5,376 KB
testcase_07 AC 335 ms
5,376 KB
testcase_08 AC 371 ms
5,376 KB
testcase_09 AC 357 ms
5,376 KB
testcase_10 AC 375 ms
5,376 KB
testcase_11 AC 360 ms
5,376 KB
testcase_12 AC 351 ms
5,376 KB
testcase_13 AC 336 ms
5,376 KB
testcase_14 AC 356 ms
5,376 KB
testcase_15 AC 348 ms
5,376 KB
testcase_16 AC 367 ms
5,376 KB
testcase_17 AC 354 ms
5,376 KB
testcase_18 AC 328 ms
5,376 KB
testcase_19 AC 374 ms
5,376 KB
testcase_20 AC 318 ms
5,376 KB
testcase_21 AC 366 ms
5,376 KB
testcase_22 AC 372 ms
5,376 KB
testcase_23 AC 365 ms
5,376 KB
testcase_24 AC 370 ms
5,376 KB
testcase_25 AC 367 ms
5,376 KB
testcase_26 AC 371 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

const int sz = 317, num = 317;

struct node{
    vec a;
    ll plus, mini;
    int id, L, R;
    node(){}
    node(int _id, vec &_a) : a(sz), plus(0), mini(INF), id(_id), L(_id * sz), R((_id + 1) * sz){
        rep(i, sz) a[i] = (i + id * sz < (int)_a.size() ? _a[i + id * sz] : INF);
        mini = *min_element(ALL(a));
    }
    void eval(bool mini_update = true){
        rep(i, sz) a[i] += plus;
        plus = 0;
        if(mini_update) mini = *min_element(ALL(a));
    }
    void update(int l, int r, ll c){
        if(R <= l || r <= L) return;
        if(l <= L && R <= r){
            plus += c;
        }else{
            eval(false);
            reps(i, max(L, l), min(R, r)) a[i - id * sz] += c;
            mini = *min_element(ALL(a));
        }
    }
    ll query(int l, int r){
        if(R <= l || r <= L) return INF;
        if(l <= L && R <= r){
            return mini + plus;
        }else{
            eval();
            ll res(INF);
            reps(i, max(L, l), min(R, r)) chmin(res, a[i - id * sz]);
            return res;
        }
    }
};

int main() {
    cin>>N;
    vec a(N);
    vector<node> group(num);
    rep(i, N) cin>>a[i];
    rep(i, num) group[i] = node(i, a);

    cin>>Q;
    rep(_, Q){
        int k, l, r, c;
        cin>>k>>l>>r>>c;
        --l;
        if(k == 1){
            rep(i, num) group[i].update(l, r, c);
        }else{
            ll res(INF);
            rep(i, num) chmin(res, group[i].query(l, r));
            cout<<res<<endl;
        }
    }
}
0