結果

問題 No.833 かっこいい電車
ユーザー merom686merom686
提出日時 2019-05-24 22:18:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 87,432 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2023-09-14 20:52:21
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
5,708 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 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 51 ms
5,908 KB
testcase_11 AC 71 ms
7,504 KB
testcase_12 AC 21 ms
4,908 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 59 ms
7,488 KB
testcase_15 AC 28 ms
5,684 KB
testcase_16 AC 23 ms
6,432 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 62 ms
6,216 KB
testcase_19 AC 22 ms
6,176 KB
testcase_20 AC 7 ms
4,476 KB
testcase_21 AC 47 ms
4,832 KB
testcase_22 AC 39 ms
8,016 KB
testcase_23 AC 26 ms
6,292 KB
testcase_24 AC 38 ms
7,728 KB
testcase_25 AC 61 ms
5,648 KB
testcase_26 AC 27 ms
6,712 KB
testcase_27 AC 43 ms
5,864 KB
testcase_28 AC 29 ms
4,508 KB
testcase_29 AC 36 ms
5,400 KB
testcase_30 AC 49 ms
8,552 KB
testcase_31 AC 34 ms
5,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    ll sum(int k) {
        ll s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<ll> b;
    int n;
};

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

    int n, q;
    cin >> n >> q;

    BIT bt(n);
    map<int, int> mp;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        bt.add(i, a);
        mp.insert(mp.end(), make_pair(i, i + 1));
    }

    for (int h = 0; h < q; h++) {
        int t, x;
        cin >> t >> x;
        x--;

        if (t == 1) {
            auto it = mp.upper_bound(x); it--;
            if (x + 1 < it->second) continue;
            int i0 = it->first;
            it = mp.erase(it);
            int i1 = it->second;
            it = mp.erase(it);
            mp.insert(it, make_pair(i0, i1));

        } else if (t == 2) {
            auto it = mp.upper_bound(x); it--;
            if (x + 1 >= it->second) continue;
            int i0 = it->first;
            int i1 = it->second;
            it = mp.erase(it);
            mp.insert(it, make_pair(i0, x + 1));
            mp.insert(it, make_pair(x + 1, i1));

        } else if (t == 3) {
            bt.add(x, 1);

        } else if (t == 4) {
            auto it = mp.upper_bound(x); it--;
            cout << bt.sum(it->second) - bt.sum(it->first) << '\n';
        }
    }

    return 0;
}
0