結果

問題 No.1234 典型RMQ
ユーザー carrot46carrot46
提出日時 2020-09-18 23:08:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,154 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 172,260 KB
実行使用メモリ 5,024 KB
最終ジャッジ日時 2023-09-27 06:42:22
合計ジャッジ時間 9,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,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 L, R;
    node(){}
    node(int id, vec &_a) : a(sz), plus(0), mini(INF), 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;
        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] += 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]);
            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