結果

問題 No.833 かっこいい電車
ユーザー veqccveqcc
提出日時 2019-05-24 23:35:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,760 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 113,564 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2023-09-14 20:57:54
合計ジャッジ時間 4,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,472 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 59 ms
9,984 KB
testcase_31 AC 43 ms
6,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

struct SegmentTree {
private:
    int n;
    vector <ll> node;

public:
    SegmentTree(int sz) {
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1, 0);
    }

    void add(int x, int val) {
        x += n - 1;
        node[x] += val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, Q;
    cin >> n >> Q;

    SegmentTree seg(n);
    for (int i = 0; i < n; i++) {
        int A;
        cin >> A;
        seg.add(i, A);
    }

    set <int> st;
    for (int i = 0; i <= n; i++) st.insert(i);


    for (int q = 0; q < Q; q++) {
        int query, x;
        cin >> query >> x;

        if (query == 1) {
            st.erase(x);
        } else if (query == 2) {
            st.insert(x);
        } else if (query == 3) {
            seg.add(x, 1);
        } else {
            auto itr = st.lower_bound(x);
            itr--;
            int l = *itr;
            int r = *st.lower_bound(x);
            cout << seg.getsum(l, r) << "\n";
        }
    }

    return 0;
}
0