結果

問題 No.833 かっこいい電車
ユーザー sykwersykwer
提出日時 2019-05-24 23:21:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 116,280 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2023-09-14 20:56:40
合計ジャッジ時間 7,145 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
5,748 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
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 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 92 ms
8,584 KB
testcase_31 AC 133 ms
5,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
const int MAX_N = 200000;

int bit[MAX_N + 1], n;

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add_to(int i, int x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

signed main() {
    int q;
    cin >> n >> q;
    vector<int> S(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> S[i + 1];
        S[i + 1] += S[i];
    }

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

    for (int i = 0; i < q; i++) {
        int query, x;
        cin >> query >> x;
        if (query == 1) {
            st.erase(st.find(x));
        } else if (query == 2) {
            st.insert(x);
        } else if (query == 3) {
            add_to(x, 1);
        } else {
            auto it = st.lower_bound(x);
            int upper = (it == st.end()) ? n : *it;
            it--;
            int lower = *it + 1;
            cout << S[upper] - S[lower - 1] + sum(upper) - sum(lower - 1) << endl;
        }

    }
    return 0;
}
0