結果

問題 No.1234 典型RMQ
ユーザー kyoprounokyoprouno
提出日時 2020-09-18 22:41:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 2,151 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 189,348 KB
実行使用メモリ 8,688 KB
最終ジャッジ日時 2023-08-08 18:49:16
合計ジャッジ時間 9,657 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 271 ms
8,308 KB
testcase_07 AC 236 ms
4,380 KB
testcase_08 AC 282 ms
8,588 KB
testcase_09 AC 260 ms
5,920 KB
testcase_10 AC 280 ms
8,392 KB
testcase_11 AC 268 ms
8,032 KB
testcase_12 AC 255 ms
5,836 KB
testcase_13 AC 235 ms
4,376 KB
testcase_14 AC 258 ms
5,776 KB
testcase_15 AC 251 ms
5,604 KB
testcase_16 AC 282 ms
8,340 KB
testcase_17 AC 257 ms
5,796 KB
testcase_18 AC 222 ms
4,376 KB
testcase_19 AC 284 ms
8,512 KB
testcase_20 AC 206 ms
8,612 KB
testcase_21 AC 272 ms
8,332 KB
testcase_22 AC 233 ms
8,516 KB
testcase_23 AC 231 ms
8,672 KB
testcase_24 AC 233 ms
8,688 KB
testcase_25 AC 232 ms
8,604 KB
testcase_26 AC 236 ms
8,524 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e18;

struct LazySegmentTree{
private:
    ll n;
    vector<ll> node, lazy;
public:
    LazySegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;
        while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        rep(i,sz) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=min(node[2*i+1],node[2*i+2]);
    }
    void eval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            if(r-l>1){
                lazy[2*k+1]+=lazy[k];
                lazy[2*k+2]+=lazy[k];
            }
            lazy[k]=0;
        }
    }
    void add(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l || r<=a) return;
        if(a<=l && r<=b){
            lazy[k]+=x;
            eval(k,l,r);
        }
        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }
    ll getmin(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return INF;
        eval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=getmin(a,b,2*k+1,l,(l+r)/2);
        ll vr=getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    LazySegmentTree seg=LazySegmentTree(a);
    ll q;
    cin >> q;
    rep(i,q){
        ll k,l,r,c;
        cin >> k >> l >> r >> c;
        l--;
        if(k==1){
            seg.add(l,r,c);
        }
        else{
            cout << seg.getmin(l,r) << endl;
        }
    }
    return 0;
}
0