結果

問題 No.833 かっこいい電車
ユーザー lightninglightning
提出日時 2019-06-01 13:29:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 3,327 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 179,792 KB
実行使用メモリ 7,628 KB
最終ジャッジ日時 2023-09-14 21:05:15
合計ジャッジ時間 5,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
5,488 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 112 ms
5,432 KB
testcase_11 AC 146 ms
7,548 KB
testcase_12 AC 48 ms
5,128 KB
testcase_13 AC 33 ms
4,376 KB
testcase_14 AC 118 ms
7,496 KB
testcase_15 AC 61 ms
5,164 KB
testcase_16 AC 48 ms
5,464 KB
testcase_17 AC 44 ms
4,376 KB
testcase_18 AC 136 ms
5,428 KB
testcase_19 AC 47 ms
5,428 KB
testcase_20 AC 14 ms
4,376 KB
testcase_21 AC 113 ms
4,380 KB
testcase_22 AC 81 ms
7,628 KB
testcase_23 AC 54 ms
5,488 KB
testcase_24 AC 80 ms
7,496 KB
testcase_25 AC 130 ms
5,172 KB
testcase_26 AC 58 ms
7,284 KB
testcase_27 AC 93 ms
5,664 KB
testcase_28 AC 67 ms
4,376 KB
testcase_29 AC 80 ms
5,252 KB
testcase_30 AC 89 ms
7,496 KB
testcase_31 AC 141 ms
5,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

template<typename T>
T upmin(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = min(l,r);
    return res;
}
template<typename T>
T upmax(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = max(l,r);
    return res;
}
template <typename T>
T upsum(const T& l,const T& r){
    return l+r;
}
template<typename T>
class SegmentTree {
public:
    using F = function<T(T&, T&)>;
    vector<T> seg;
    int sz = 1;
    T unit;
    F up;
    //T (*up)(const T& l,const T& r);
    SegmentTree(int n, F up, T unit = 0) {
        this->unit = unit;
        //int sz = 1;
        while (sz < n) sz <<= 1;
        seg.resize(sz * 2, unit);
        this->up = up;
    }
    void set(const int& k, const T& x) {//左からk番目の葉にxを代入する
        seg[sz - 1 + k] = x;
    }
    T get(const int& k) {//左からk番目の葉を得る
        return seg[sz - 1 + k];
    }
    void update(int k, const T& v) {// k 番目の値をvに変更
        k += sz - 1;
        seg[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = up(seg[2 * k + 1], seg[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l,int r) {//[a,b)のupの合成を求める(a,b,0,0,sz)のように使う
        if (r <= a || b <= l) {
            return unit;
        }
        if (a <= l && r <= b) {
            return seg[k];
        }
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return up(vl, vr);
        }
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    SegmentTree<int> sgmin(n,upmin<int>,n);
    SegmentTree<int> sgmax(n,upmax<int>,-1);
    SegmentTree<ll> sgsum(n,upsum<ll>,0);
    
    Rep(i,n){
        cin >> a[i];
        sgsum.update(i,a[i]);
        sgmin.update(i,i);
        sgmax.update(i,i);
    }
    Rep(i,q){
        int y,x;
        cin >> y >> x;
        x--;
        if(y==1){
            sgmin.update(x,n);
            sgmax.update(x+1,0);
            
        }else if(y==2){
            sgmin.update(x,x);
            sgmax.update(x+1,x+1);
            
        }else if(y==3){
            sgsum.update(x,sgsum.get(x)+1);
        }else{
            int a = sgmax.query(0,x+1,0,0,sgmin.sz);
            int b = sgmin.query(x,sgmax.sz,0,0,sgmax.sz);
            ll res = sgsum.query(a,b+1,0,0,sgsum.sz);
            put(res);
        }
    }
    return 0;
}
0