結果

問題 No.259 セグメントフィッシング+
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-05 15:27:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,377 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 201,728 KB
実行使用メモリ 6,312 KB
最終ジャッジ日時 2023-10-11 10:08:06
合計ジャッジ時間 6,691 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 121 ms
6,268 KB
testcase_09 AC 122 ms
6,208 KB
testcase_10 AC 122 ms
6,212 KB
testcase_11 AC 122 ms
6,272 KB
testcase_12 AC 123 ms
6,156 KB
testcase_13 AC 133 ms
6,148 KB
testcase_14 AC 131 ms
6,148 KB
testcase_15 AC 132 ms
6,084 KB
testcase_16 AC 132 ms
6,152 KB
testcase_17 AC 131 ms
6,208 KB
testcase_18 AC 133 ms
6,084 KB
testcase_19 AC 132 ms
6,208 KB
testcase_20 AC 133 ms
6,312 KB
testcase_21 AC 133 ms
6,156 KB
testcase_22 AC 131 ms
6,148 KB
testcase_23 AC 77 ms
4,348 KB
testcase_24 AC 96 ms
6,212 KB
testcase_25 AC 96 ms
6,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <typename T>
class BinaryIndexedTree {
    vector<T> data;
    int n;
    //
public:
    BinaryIndexedTree(int n_) : n(n_ + 2), data(n_ + 2, 0) {}
    T sum(int i) {
        T ret(0);
        for (int x = i + 1; x > 0; x -= x & -x)
            ret += data[x];
        return ret;
    }
    void add(int i, T a) {
        for (int x = i + 1; x <= n; x += x & -x) {
            data[x] += a;
        }
    }
    T query(int a, int b) {
        return sum(b) - sum(a - 1);
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;

    BinaryIndexedTree<ll> bit(N * 2 + 1);
    int origin = 0;

    auto rem = [&](int a) {
        return (((a += origin) %= 2 * N) += 2 * N) %= 2 * N;
    };

    auto get = [&](int a, int b) {
        if (a <= b) {
            return bit.query(a, b);
        } else {
            return bit.query(a, N * 2 - 1) + bit.query(0, b);
        }
    };

    while (Q--) {
        char c;
        int t, y, z;
        cin >> c >> t >> y >> z;

        (((origin = -t) %= 2 * N) += 2 * N) %= 2 * N;

        if (c == 'L') {
            bit.add(rem(2 * N - 1 - y), z);
        } else if (c == 'R') {
            bit.add(rem(y), z);
        } else {
            z--;
            cout << get(rem(y), rem(z)) + get(rem(2 * N - 1 - z), rem(2 * N - 1 - y)) << endl;
        }
    }
}
0