結果

問題 No.833 かっこいい電車
ユーザー sykwersykwer
提出日時 2019-05-24 23:32:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,937 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 115,728 KB
実行使用メモリ 9,084 KB
最終ジャッジ日時 2023-09-14 20:57:35
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
5,772 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 116 ms
6,588 KB
testcase_11 AC 155 ms
8,040 KB
testcase_12 AC 48 ms
5,228 KB
testcase_13 AC 32 ms
4,376 KB
testcase_14 AC 128 ms
8,136 KB
testcase_15 AC 62 ms
6,104 KB
testcase_16 AC 53 ms
7,072 KB
testcase_17 AC 42 ms
4,376 KB
testcase_18 AC 139 ms
6,548 KB
testcase_19 AC 49 ms
6,608 KB
testcase_20 AC 13 ms
4,388 KB
testcase_21 AC 108 ms
4,820 KB
testcase_22 AC 87 ms
9,084 KB
testcase_23 AC 57 ms
6,852 KB
testcase_24 AC 86 ms
8,356 KB
testcase_25 AC 129 ms
6,016 KB
testcase_26 AC 60 ms
7,036 KB
testcase_27 AC 95 ms
6,344 KB
testcase_28 AC 67 ms
4,732 KB
testcase_29 AC 81 ms
5,684 KB
testcase_30 AC 89 ms
8,580 KB
testcase_31 AC 128 ms
5,756 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) {
            auto it = st.find(x);
            if (it != st.end()) {
                st.erase(it);
            }
        } 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