結果

問題 No.833 かっこいい電車
ユーザー face4face4
提出日時 2019-12-08 14:35:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,150 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 81,324 KB
実行使用メモリ 8,572 KB
最終ジャッジ日時 2023-08-28 21:28:47
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
5,624 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 127 ms
5,956 KB
testcase_11 AC 168 ms
7,444 KB
testcase_12 AC 50 ms
4,840 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 135 ms
7,644 KB
testcase_15 AC 67 ms
5,632 KB
testcase_16 AC 53 ms
6,464 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 149 ms
6,116 KB
testcase_19 AC 51 ms
6,208 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 120 ms
4,576 KB
testcase_22 AC 90 ms
8,048 KB
testcase_23 AC 59 ms
6,156 KB
testcase_24 AC 90 ms
7,744 KB
testcase_25 AC 141 ms
5,688 KB
testcase_26 AC 63 ms
6,688 KB
testcase_27 AC 102 ms
5,860 KB
testcase_28 AC 71 ms
4,404 KB
testcase_29 AC 85 ms
5,528 KB
testcase_30 AC 98 ms
8,572 KB
testcase_31 AC 133 ms
5,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;

struct BIT{
    int n;
    vector<ll> v;

    BIT(int x) : n(x){
        v.resize(n+1, 0);
    }

    void add(int x, int val){
        while(x <= n){
            v[x] += val;
            x += x&-x;
        }
    }

    ll query(int x){
        ll ret = 0;
        while(x > 0){
            ret += v[x];
            x -= x&-x;
        }
        return ret;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    BIT bit(n);
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        bit.add(i+1, x);
    }
    set<int> fr;
    for(int i = 1; i <= n+1; i++) fr.insert(i);
    while(q-- > 0){
        int a, b;
        cin >> a >> b;
        if(a == 1){
            if(fr.count(b+1)){
                fr.erase(b+1);
            }
        }else if(a == 2){
            if(fr.count(b+1)==0){
                fr.insert(b+1);
            }
        }else if(a == 3){
            bit.add(b, 1);
        }else if(a == 4){
            cout << bit.query(*(fr.upper_bound(b))-1) - bit.query(*(--fr.upper_bound(b))-1) << endl;
        }
    }
    return 0;
}
0