結果

問題 No.833 かっこいい電車
ユーザー Shuz*Shuz*
提出日時 2019-04-20 23:10:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 169,484 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-09-14 16:06:19
合計ジャッジ時間 4,384 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 16 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 5 ms
4,376 KB
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 32 ms
4,684 KB
testcase_31 AC 35 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0, _##i = (n); i < _##i; ++i)

struct BIT {
    vector<ll> data;

    BIT() {}
    BIT(int N) : data(N + 1) {
        fill(data.begin(), data.end(), 0);
        data[0] = N;
    }

    inline void add(int pos, int val) {
        while (pos <= data[0]) {
            data[pos] += val;
            pos += pos & -pos;
        }
    }
    inline ll sum(int pos) {
        if (pos <= 0) return 0;
        ll res = 0;
        while (pos > 0) {
            res += data[pos];
            pos -= pos & -pos;
        }
        return res;
    }

    inline int lower_bound(int val) {
        if (val <= 0) return 0;
        int index = 0;
        for (int d = 1 << int(log2(data[0])); d > 0; d /= 2) {
            if (index + d <= data[0] && data[index + d] < val) {
                val -= data[index + d];
                index += d;
            }
        }
        return index;
    }
};

struct GCT {
    int size;
    BIT bit;

    GCT(int N) : bit(N), size(N) {
        for (int i = 1; i <= bit.data[0]; i++) {
            bit.data[i] = i & -i;
        }
    }

    inline int group_index(int index) { return bit.sum(index + 1) - 1; }
    inline int dist(int x, int y) { return abs(group_index(x) - group_index(y)); }

    inline int begin(int group_index) { return bit.lower_bound(group_index + 1); }
    inline int end(int group_index) { return bit.lower_bound(group_index + 2); }
    inline int group_size(int group_index) {
        return end(group_index) - begin(group_index);
    }

    inline void group(int index) {
        int s = -(bit.sum(index + 2) - bit.sum(index + 1));
        bit.add(index + 2, s);
        size += s;
    }
    inline void cut(int index) {
        int s = !(bit.sum(index + 2) - bit.sum(index + 1));
        bit.add(index + 2, s);
        size += s;
    }
};

int main() {
    int N, Q;
    scanf("%d %d", &N, &Q);
    int A, B;
    BIT bit(N);
    GCT gct(N);
    rep(i, N) scanf("%d", &A), bit.add(i + 1, A);
    rep(i, Q) {
        scanf("%d %d", &A, &B);
        if (A == 1) {
            gct.group(B - 1);
        } else if (A == 2) {
            gct.cut(B - 1);
        } else if (A == 3) {
            bit.add(B, 1);
        } else {
            int index = gct.group_index(B - 1);
            printf("%d\n", bit.sum(gct.end(index)) - bit.sum(gct.begin(index)));
        }
    }
}
0